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:
Copy codeThe Code is as follows:
<Body>
<Div class = "main">
<Div id = "showpane" class = "showpane"> </div>
<Div class = "textarea">
<Form method = "post" action = "" name = "sform">
<Textarea name = "txtara"> </textarea>
<Div>
<Input type = "submit" name = "subt" value = "send" onclick = "doAjax(sform.txt ara. value); return false;"/>
</Div>
</Form>
</Div>
</Div>
</Body>
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!
Copy codeThe Code is as follows:
<Body>
<Div class = "main">
<Div id = "showpane" class = "showpane">
</Div>
<Div class = "textarea">
<Form method = "post" action = "" name = "sform">
<Textarea name = "txtara"> </textarea>
<Div>
<Input type = "submit" name = "subt" value = "send" onclick = "doAjax(sform.txt ara. value, this); return false;"/>
</Div>
</Form>
</Div>
</Div>
</Body>
JavaScript:
Copy codeThe 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!