(turn) in the Web page JS function automatic execution commonly used three kinds of methods

Source: Internet
Author: User

Original: http://blog.sina.com.cn/s/blog_6f6b4c3c0100nxx8.html in the Web page JS function automatic execution commonly used three kinds of methods in the Web page JS function automatic execution commonly used three kinds of methods

In the head area of HTML, there are the following functions:

<script language= "JavaScript" >

Functionn Myautorun () {

The following is the code of your function, please modify it yourself first!

Alert ("Function automatic execution Oh!") ");

}

</SCRIPT>

Next, let's run it automatically when the page loads on the function above!

  The first method of ①

Change the above code to:

<script language= "JavaScript" >

Functionn Myautorun () {

The following is the code of your function, please modify it yourself first!

Alert ("Function automatic execution Oh!") ");

}

Window.onload=myautorun (); I just need to add this sentence

</SCRIPT>

  The second method of ②

The body of the modified Web page is:

  <body onload= "Myautorun (); >

or instead:

  <body onload= "Javascript:myautorun (); >

  The third method of ③

Use the JS timer to perform discontinuous functions:

SetTimeout ("Myautorun ()", 1000); Executes the Myautorun () function once every 1000 milliseconds

Implementation method, the top of the JS function, instead:

<script language= "JavaScript" > Functionn myautorun () {

The following is the code of your function, please modify it yourself first! Alert ("Function automatic execution Oh!") ");

}

setTimeout ("Myautorun ()", +); That's it, pull.

</SCRIPT>

Other methods are more special, also not commonly used, the generality is not big, do not introduce!

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.