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!