As needed, I need to use setTimeout () and pass a parameter in the function parameter, just like setTimeout (& quot; fun (parameter) & quot;, 1000 ). However, in my writing, js will report an error saying that the 'parameter' is not defined. So I searched the internet and used another method, setTimeout ("fun (" + parameter + ")", 1000, however, the preceding method is applicable when passing form textarea. For example, hml is like this:
The Code is as follows:
In js, I can write like this:
SetTimeout ("doAjax(document.sform.txt ara. value)", 1000 );
However, if you want to pass other parameters or object parameters, You need to rewrite this function according to the method provided on the Internet.
After research and practice, I have improved my methods. You can refer to it for reference. I only rely on my personal needs. I cannot guarantee other situations. Please give me more advice!
The Code is as follows:
JavaScript:
The Code is as follows:
Function initAjax (){
Var httprequest = null;
Try {
Httprequest = new ActiveXObject ("Msxml2.XMLHTTP ");
}
Catch (e ){
Try {
Httprequest = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Catch (e ){
Try {
Httprequest = new XMLHttpRequest ();
}
Catch (e ){
Httprequest = null;
}
}
}
Return httprequest;
}
Function doAjax (msg, obj ){
Var obj = obj; // This line is the main line.
Alert (obj. value );
Var he = "he =" + msg;
Var ajaxrequest = initAjax ();
Ajaxrequest. open ("POST", "abc. jsp", true );
Ajaxrequest. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded; charset = UTF-8 ");
Ajaxrequest. send (he );
Ajaxrequest. onreadystatechange = function (){
If (ajaxrequest. readyState = 4 ){
If (ajaxrequest. status = 200 ){
Document. getElementById ("showpane"). innerHTML = ajaxrequest. responseText;
}
Else {
DoAjax (msg );
}
}
}
SetTimeout ("doAjax(document.sform.txt ara. value, document. all [" + obj. sourceIndex + "])", 100); // there is also this line
}
In this way, I solved the problem of passing object parameters. Finally, I would like to say that I would like to comment on a better solution. I would like to learn from like-minded people!