One page output
1. Header file
< ;head>
2. Copy the code within the page
<script> <br>document.write("Script Home"); <br></script>
3. External file
4. InnerHtml using page ID
<script> <br>window.onload = writeMessage; // Call the writeMessage function when the page is loaded<br>writeMessage( ) { <br>document.getElementById("helloMessage").innerHTML = "Script Home"; <br>//Find the dom ID (helloMessage) and modify its html content<br>} <br></script>
5. Warning
alert("Guangzhou Baihui Logistics Co., Ltd.");
6. Inquiry
if (confirm("Do you want to visit our homepage"))
{
alert("Yes, go to") ;
}
else {
alert("Exit");
}
7. Enter
var ans = prompt("Enter your message","Hello,");
if (ans) {
alert("You said:" ans);
}
else {
alert("Exit, no message");
}
8. Page jump Transfer
<script> <br>window.onload = initAll; <br>function initAll() { <br>document.getElementById("redirect").onclick = initRedirect; <br>} <br>function initRedirect() <br>{ <br>window.location = "index .html"; <br>return false; <br>} <br></script>
Script of Home
9. Judgment branch
<script> <br>window.onload = initAll; <br>function initAll() { <br>document.getElementById("Lincoln").onclick = saySomething; <br>document.getElementById ("Kennedy").onclick = saySomething; <br>document.getElementById("Nixon").onclick = saySomething; <br>} <br>function saySomething() { <br>switch(this.id) { <br>case "Lincoln": <br>alert("Four score and seven years ago..."); <br>break; <br>case "Kennedy": <br>alert("Ask not what your country can do for you..."); <br>break; <br>case "Nixon": <br>alert("I am not a crook!"); <br>break; <br>default: <br>} <br>} <br></script>
10. Exception catching
window.onload = initAll;
function initAll() {
var ans = prompt("Input parameters: ","");
try {
if (!ans || isNaN(ans) || ans<0) {
throw new Error("The input is not a number");
}
alert("root sign" ans " yes " Math.sqrt(ans));
}
catch (errMsg) {
alert(errMsg.message);
}
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn