Let's take a look at two simple small examples.
SetTimeout () usage:
[Javascript]
<Script language = "JavaScript">
Function test (){
// Execute the sleep method after 100 milliseconds, but the 100 milliseconds program will not wait and will continue to execute the code after setTimeout
// The effect is first alert (2); then alert (1 );
Window. setTimeout ("sleep ()", 100 );
Alert (2 );
}
Function sleep (){
Alert (1 );
}
Test ();
</SCRIPT>
The first parameter of the setTimeout method can be a string or a pointer to a method.
If it is a string, parentheses must be written, and no parentheses must be written for the pointer,
For example:
[Javascript]
Window. setTimeout ("sleep ()", 100 );
Window. setTimeout (sleep, 100 );
The two have the same effect.
You can also specify parameters, such
[Javascript]
Window. setTimeout ("sleep ('" + document. all. aa. value + "')", 100 );
Window. setTimeout (sleep (document. all. aa. value), 100 );
Then, you can obtain the parameter value in the sleep method.
Let's look at window. setInterval ():
[Javascript] view plaincopy
<Script language = "JavaScript">
Var timer; // declare a timer
Var count = 0;
Function test ()
{
// Execute the add () method once every 500 milliseconds
Timer = window. setInterval ("add ()", 500 );
}
Function add (){
Alert (++ count );
If (count = 5)
{
// If the count value reaches 5, clear the timer
Window. clearInterval (timer );
}
}
Test ();
</SCRIPT>
The application automatically identifies the encryption lock in the encryption lock and monitors the insertion of the encryption lock at any time.
[Javascript]
<Span style = "white-space: pre"> </span> // sets the global timer variable and stops timer when the encryption lock is found.
Var timer;
Function IA300_GetInstance ()
{
If (_ IA300Client = null)
{
_ IA300Client = document. getElementById ("IA300Client ");
}
_ IA300Client. Model = 0;
Return _ IA300Client;
}
Var flag = false;
// Call this function during page loading
Function OnPageLoad (){
Var browser = DetectBrowser ();
If (browser = "Unknown "){
Alert ("This browser is not supported. If you are using a proud game or similar browser, switch to IE mode ");
Return;
}
// CreateAdminElementIA300 () Add the IA300 plug-in to this page
CreateElementIA300 ();
// DetectActiveX () determines whether IA300Admin is installed
Var create = DetectIA300Plugin ();
If (create = false ){
Alert ("the plug-in is not installed. Please install the management plug-in under the Development Kit Plugin folder. ");
Return false;
}
}
// Find the local
Function IA300Find (){
Var rtn = IA300_CheckExist ();
If (0 <rtn ){
/* Alert ("find" + rtn + "to lock. Please select the encryption lock you need to set in the list. Be sure to exclude the Administrator lock on your own! ");*/
Document. getElementById ("userUK"). options. length = 0; // initialize the list
For (I = 0; I <rtn; I ++) {// obtain all the encryption lock hardware IDS
Var id = IA300_GetHardwareId (I );
If (id = ""){
Alert ("get number" + (1 + I) + "failed to lock hardware ID, error code :"
+ IA300_GetLastError ());
} Else {
Document. getElementById ("userUK"). options [I] = new Option (
Id, id );
Alert ("password lock detected. Please log on! ");
// The encryption lock is detected to exit timer.
If (document. getElementById ("userUK"). options [I]. value = id ){
Window. clearInterval (timer );
}
}
}
} Else {
// Alert ("no encryption lock found! ");
Document. getElementById ("userUK"). options. length = 0;
Document. getElementById ("userUK"). options [0] = new Option (
"");
Return false;
}
}
// Start checking timer
Function IA300_StartCheckTimer (interval)
{
// _ TimerErrorMessage = errMsg;
// _ ExpireUrl = logonUrl;
// Timed Detection
Timer = window. setInterval (IA300Find, interval );
}
[Javascript]
<Span style = "white-space: pre"> </span> // run the preceding two js methods when the page is loaded.
[Javascript] view plaincopy
<Span style = "white-space: pre"> </span> $ (document). ready (function (){
OnPageLoad ();
IA300_StartCheckTimer (500 );
});