Home > Web Front-end > JS Tutorial > JavaScript Basics Chapter 1 JavaScript and Client_Basic Knowledge

JavaScript Basics Chapter 1 JavaScript and Client_Basic Knowledge

WBOY
Release: 2016-05-16 18:22:34
Original
1000 people have browsed it

One page output
1. Header file

Copy code The code is as follows:

< ;head>


2. Copy the code within the page
The code is as follows:


<script> <br>document.write("Script Home"); <br></script>


3. External file

4. InnerHtml using page ID
Copy code The code is as follows:

<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
Copy code The code is as follows:

if (confirm("Do you want to visit our homepage"))
{
alert("Yes, go to") ;
}
else {
alert("Exit");
}

7. Enter
Copy code The code is as follows:

var ans = prompt("Enter your message","Hello,");
if (ans) {
alert("You said:" ans);
}
else {
alert("Exit, no message");
}

8. Page jump Transfer
Copy code The code is as follows:

<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
Copy code The code is as follows:

<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>


type="button" id="Kennedy" value="Kennedy" />
value="Nixon" />


10. Exception catching
Copy code The code is as follows:

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);
}
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template