Examples of AJAX

Source: Internet
Author: User

Two reference methods:

Code:
  1. // 1
  2. <Script language = "JavaScript">
  3. Window. Alert ("welcome to the scripting language! ");
  4. </SCRIPT>
  5. // 2
  6. <Script language = "JavaScript" src = "init. js"> </SCRIPT>

// ========== 1. Implement rich page interaction effects with JavaScript (using the scroll subtitle <marquee> component ).

Code:
  1. <Body>
  2. <Marquee onmouseover = "this. Stop ()" onmouseout = "This. Start ()" scrolldelay = 110>
  3. <A href = "" target = _ blank>
  4. <Font color = # ff0000> hot news: Ajax has become a new favorite of Internet technologies </font>
  5. </A> </marquee> <br>
  6. </Body>

// =========== 2. Verify the submitted content. Use Dom to obtain data in form.

Code:
  1. <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
  2. <HTML>
  3. <Head>
  4. <Title> 3-3.html </title>
  5. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
  6. <Script language = "JavaScript">
  7. Function checkvalid ()
  8. {
  9. VaR tmp1, temp2, str1;
  10. // Obtain the value of text1
  11. Str1 = Document. myform. Email. value;
  12. // Obtain the location of the First @
  13. Tmp1 = str1.indexof ('@');
  14. // Obtain the location of the last @
  15. Tmp2 = str1.lastindexof ('@');
  16. If (str1.length = 0)
  17. // Invalid. The string is an empty string.
  18. Window. Alert ("Enter the content before submitting ");
  19. Else if (tmp1 <0)
  20. // Invalid. The string does not contain the @ character
  21. Window. Alert ("the string does not contain @");
  22. Else if (tmp1 = 0 | tmp1 = str1.length-1)
  23. // Invalid. The position of the @ character is incorrect.
  24. Window. Alert ("@ the wrong position of the character ");
  25. Else if (tmp1! = Tmp2)
  26. // Invalid. The @ character contains more than one
  27. Window. Alert ("@ character appears more than one ");
  28. Else
  29. // Valid email address
  30. Alert ("the email address is valid ");
  31. }
  32. </SCRIPT>
  33. </Head>
  34. <Body>
  35. <Form name = "myform">
  36. Enter your email address: <br>
  37. <Input type = text value = "" name = "email">
  38. <P> <input type = button value = "Submit" name = "OK" onclick = "checkvalid ()">
  39. </Form>
  40. </Body>
  41. </Html>

// --------- 3. event-driven list box ---------------------

Code:
  1. <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
  2. <HTML>
  3. <Head>
  4. <Title> 3-4.html </title>
  5. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
  6. <Script language = "JavaScript">
  7. // Function called when the selected option in the list box changes
  8. Function Change ()
  9. {
  10. // Display different author information based on the selected options
  11. Switch (myform. option1.value)
  12. {
  13. Case "S1 ":
  14. Myform.txt 1. value = "Zhang guiyuan ";
  15. Break;
  16. Case "S2 ":
  17. Myform.txt 1. value = "Jia yanfeng ";
  18. Break;
  19. Case "S3 ":
  20. Myform.txt 1. value = "Zhang Yuxiang ";
  21. Break;
  22. }
  23. }
  24. </SCRIPT>
  25. </Head>
  26. <Body>
  27. <P> query the author information:
  28. <Form name = "myform">
  29. <Select type = "select" name = "option1" onchange = "Change ()">
  30. <Option selected value = "S0"> <----- select -----> </option>
  31. <Option value = "S1"> Web 2.0 development entry and Practice (Java) </option>
  32. <Option value = "S2"> Web 2.0 development entry and Practice (. NET) </option>
  33. <Option value = "S3"> Ajax core technology </option>
  34. </SELECT>
  35. <Input type = "text" name = "txt1" value = "">
  36. </Form>
  37. </Body>
  38. </Html>

Effect: select different options in the list box. The corresponding information of the author is displayed in the text box.

// 4 ---------

Code:
  1. <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
  2. <HTML>
  3. <Head>
  4. <Title> 3-5.html </title>
  5. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
  6. <Script language = "JavaScript">
  7. Function Init ()
  8. {
  9. Alert ("Welcome! ");
  10. }
  11. Function finish ()
  12. {
  13. Alert ("next time! ");
  14. }
  15. </SCRIPT>
  16. </Head>
  17. <Body onload = "Init ()" onUnload = "finish ()">
  18. </Body>
  19. </Html>

You can use the onload event to interact with the database.

// ------------------- 5 onfoucs event and onblur Event Focus event -------------------

Code:
  1. <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
  2. <HTML>
  3. <Head>
  4. <Title> 3-6.html </title>
  5. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
  6. <Script language = "JavaScript">
  7. Function begin ()
  8. {
  9. Usrid. value = "";
  10. }
  11. Function end ()
  12. {
  13. Alert ("Please confirm the entered information. Thank you! ");
  14. }
  15. </SCRIPT>
  16. </Head>
  17. <Body>
  18. <Input type = "text" value = "Enter the user name" name = "usrid" onfocus = "begin ()" onblur = "end ()">
  19. </Body>
  20. </Html>

// Effect: first, display the preset content in the text box. Insert the content based on the cursor. the preset content disappears!

=================================== JavaScript event summary ====================== ====

 

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.