Chapter 1 javascript and client

Source: Internet
Author: User

1. Page output
1. header file
Copy codeThe Code is as follows:
<Head>
<Script language = "javascript">
Document. write (" www.www.jb51.net ");
</Script>
</Head>

2. on the page
Copy codeThe Code is as follows:
<Body>
<Script>
Document. write (" ");
</Script>
</Body>

3. External files
<Script src = "display. js"> </script>
4. Use innerHtml of the page ID
Copy codeThe Code is as follows:
<Script>
Window. onload = writeMessage; // call the writeMessage function during page loading.
WriteMessage (){
Document. getElementById ("helloMessage"). innerHTML = "";
// Locate the dom ID (helloMessage) and modify its html content
}
</Script>

5. Warning
Alert ("Guangzhou Baihui logistics Co., Ltd ");
6. Ask
Copy codeThe Code is as follows:
If (confirm ("whether to visit our Homepage "))
{
Alert ("yes, go ");
}
Else {
Alert ("quit ");
}
7. Enter
Copy codeThe 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
Copy codeThe Code is as follows:
<Script>
Window. onload = initAll;
Function initAll (){
Document. getElementById ("redirect"). onclick = initRedirect;
}
Function initRedirect ()
{
Window. location = "index.html ";
Return false;
}
</Script>
<A href = "http://www.jb51.net" id = "redirect"> foot home </a>

9. Determine the branch
Copy codeThe Code is as follows:
<Script>
Window. onload = initAll;
Function initAll (){
Document. getElementById ("Lincoln"). onclick = saySomething;
Document. getElementById ("Kennedy"). onclick = saySomething;
Document. getElementById ("Nixon"). onclick = saySomething;
}
Function saySomething (){
Switch (this. id ){
Case "Lincoln ":
Alert ("Four score and seven years ago ...");
Break;
Case "Kennedy ":
Alert ("Ask not what your country can do for you ...");
Break;
Case "Nixon ":
Alert ("I am not a crook! ");
Break;
Default:
}
}
</Script>
<Form action = "#">
<Input type = "button" id = "Lincoln" value = "Lincoln"/>
<Input
Type = "button" id = "Kennedy" value = "Kennedy"/>
<Input type = "button" id = "Nixon"
Value = "Nixon"/>
</Form>

10. Exception capture
Copy codeThe Code is as follows:
Window. onload = initAll;
Function initAll (){
Var ans = prompt ("input parameter :","");
Try {
If (! Ans | isNaN (ans) | ans <0 ){
Throw new Error ("input is not a number ");
}
Alert ("root" + ans + "yes" + Math. sqrt (ans ));
}
Catch (errMsg ){
Alert (errMsg. message );
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.