vCode Required. Variant that specifies the function pointer or string that indicates the code to be executed when the specified interval has elapsed.
iMilliSeconds Required. Integer that specifies the number of milliseconds.
sLanguage Optional. String that specifies one of the following values: JScript Language is JScript.
VBScript Language is VBScript.
JavaScript Language is JavaScript.
以下是MSDN上的例子!
The following example uses the setTimeout method to evaluate a simple expression after one second has elapsed.
window.setTimeout("alert('Hello, world')", 1000);
The following example uses the setTimeout method to evaluate a slightly more complex expression after one second has elapsed.
var sMsg = "Hello, world";
window.setTimeout("alert(" + sMsg + ")", 1000);
This example uses the setTimeout method to hide a input type=button object after three seconds. If the user clicks the Count Down button and then counts to three, the Now You See Me button disappears.
<SCRIPT>
function fnHide(oToHide){
window.setTimeout("fnHide2(" + oToHide.id + ")", 3000);
}
function fnHide2(sID){
var o = eval(sID);
o.style.display="none";
}
</SCRIPT>
<INPUT TYPE=button VALUE="Count Down"
ID="oHideButton" onclick="fnHide(this)">
This example uses a function pointer to pass the data. In this case, the data is stored in a global variable because it cannot be passed directly. In the preceding example, the ID of the button is passed as a parameter to the function invoked by the setTimeout method. This is possible only when a string is passed as the first argument.