Example of JS request value and Automatic Execution

Source: Internet
Author: User

Three common methods for automatically executing JS functions on webpages
In the Head area of HTML, there are the following functions:
Copy codeThe Code is as follows:
<Script language = "JavaScript">
Functionn MyAutoRun ()
{
// The following is the code of your function. Please modify it first!
Alert ("automatic function execution! ");
}
</SCRIPT>

Next, let's take a look at the above functions to make them automatically run when loading webpages!
① Method 1
Change the code above:
Copy codeThe Code is as follows:
<Script language = "JavaScript">
Functionn MyAutoRun ()
{
// The following is the code of your function. Please modify it first!
Alert ("automatic function execution! ");
}
Window. onload = MyAutoRun (); // you only need to add this sentence
</SCRIPT>

② Method 2
Modify the webpage Body:
Copy codeThe Code is as follows:
<Body onLoad = "MyAutoRun ();">

Or change:
Copy codeThe Code is as follows:
<Body onLoad = "javascript: MyAutoRun ();">

③ Method 3
Use the JS timer to execute intermittent functions:
Copy codeThe Code is as follows:
SetTimeout ("MyAutoRun ()", 1000); // execute the MyAutoRun () function once every 1000 milliseconds

Implementation Method: Change the JS function at the top:
Copy codeThe Code is as follows:
<Script language = "JavaScript">
Functionn MyAutoRun ()
{
// The following is the code of your function. Please modify it first!
Alert ("automatic function execution! ");
}
SetTimeout ("MyAutoRun ()", 1000); // This way you can pull
</SCRIPT>

Other methods are special and not commonly used. They are not widely used!
EL & JSTL can also be used in JS.
Copy codeThe Code is as follows:
Var step = "<c: out value = '$ {step}' default = '0'/> ";
Switch (step ){
Case "0 ":
Default:
Break; var step = "<c: out value = '$ {step}' default = '0'/> ";

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.