When a form is submitted, it is based on the name attribute of the element. As long as the name attribute is not added, it will not be submitted. The specific implementation is as follows, if you are interested, you can refer to the elements whose submitted values are not empty.
Can be used for query
Code:
The Code is as follows:
// When executing the query, if the field in the form is blank, It is not submitted.
$ ("# Form1"). submit (function (){
Try {
$ (This). find ("*"). each (function (){
Var elem = $ (this );
If (elem. prop ("name ")! = Null & elem. prop ("name ")! = ""){
If (elem. val () = ""){
Elem. removeAttr ("name ");
}
}
});
} Catch (e ){
Alert (e );
}
Return true;
});
Note that only one is returned. The form submit method takes the bool value. If one is not returned by default, it is void.
Principle: When a form is submitted, it is based on the name attribute of the element. As long as the name attribute is not added, It is not submitted.
The first step is to find all elements, that is, *, and then judge whether the name attribute is not null or not empty.
After the element is obtained, if the value is null, the name attribute is removed.