JS takes the value of request and executes it automatically using the example
- 2020-03-30 02:06:33
- OfStack
There are three common ways to automate JS functions in web pages
In the Head area of HTML, there is the following function:
Next, let's take the above function and let it run automatically when the page loads!
The first method
Change the above code to:
The second method
Modify the Body of the page to:
Or replace it with:
The third way
Using JS timer to intermittently execute functions:
To implement the method, change the top JS function to:
Other methods are more special, not commonly used, versatility is not big, not introduced!
You can also use EL& JSTL in JS
In the Head area of HTML, there is the following function:
<SCRIPT LANGUAGE="JavaScript">
functionn MyAutoRun()
{
//The following is the code of your function, please modify first!
alert(" The function executes automatically! ");
}
</SCRIPT>
Next, let's take the above function and let it run automatically when the page loads!
The first method
Change the above code to:
<SCRIPT LANGUAGE="JavaScript">
functionn MyAutoRun()
{
//The following is the code of your function, please modify first!
alert(" The function executes automatically! ");
}
window.onload=MyAutoRun(); //Just add this sentence
</SCRIPT>
The second method
Modify the Body of the page to:
<body onLoad="MyAutoRun();">
Or replace it with:
<body onLoad="javascript:MyAutoRun();">
The third way
Using JS timer to intermittently execute functions:
setTimeout("MyAutoRun()",1000); //The MyAutoRun() function is executed every 1000 milliseconds
To implement the method, change the top JS function to:
<SCRIPT LANGUAGE="JavaScript">
functionn MyAutoRun()
{
//The following is the code of your function, please modify first!
alert(" The function executes automatically! ");
}
setTimeout("MyAutoRun()",1000); //That's it
</SCRIPT>
Other methods are more special, not commonly used, versatility is not big, not introduced!
You can also use EL& JSTL in JS
var step = "<c:out value='${step}' default='0'/>";
switch(step) {
case"0":
default:
break; var step = "<c:out value='${step}' default='0'/>";