In some cases, the same form can be submitted to different processing actions under different circumstances, and the attributes of the form can be dynamically changed in js to meet the requirements of form submission for different conditions.
For example:
Copy codeThe Code is as follows:
<Form id = "form" name = "form" method = "POST" enctype = "multipart/form-data" action = "action1.jsp" target = "iframe">
<Input type = "file" name = "file" id = "file" class = "input_text80"> </input>
<Input id = "name" name = "name"/>
<Input type = "button" value = "Update to probe point" onClick = "javascript: formSubmit ();"> </input>
</Form>
<Iframe name = "iframe"> </iframe>
If condition 1 is required, submit the statement in the preceding method, use method = "POST" enctype = "multipart/form-data" action = "action1.jsp" target = "iframe" to submit it to action1.jsp for processing; under Condition 2, you need to submit it to action2.jsp for processing in plain text mode and open a new page. You need to dynamically change the form attributes in js mode:
Copy codeThe Code is as follows:
Function formSubmit (){
If (flag = "1 "){
$ ("# Form"). submit ();
} Else if (flag = "2 "){
$ ("# Form"). attr ("action", "deployResult. jsp ");
$ ("# Form"). attr ("target", "_ blank ");
$ ("# Form"). attr ("method", "GET ");
$ ("# Form"). attr ("enctype", "application/x-www-form-urlencoded ");
$ ("# Form"). attr ("encoding", "application/x-www-form-urlencoded ");
$ ("# Form"). submit ();
}
}
Note:
When you change the enctype attribute of form, if you only write $ ("# form"). attr ("enctype", "application/x-www-form-urlencoded ");
It will not take effect. You must combine the following two sentences to make it take effect:
Copy codeThe Code is as follows:
$ ("# Form"). attr ("enctype", "application/x-www-form-urlencoded ");
$ ("# Form"). attr ("encoding", "application/x-www-form-urlencoded ");
For more information about the attribute values of enctype, see HTML <form> label's enctype attribute.