Elements whose jquery submission value is not empty

Source: Internet
Author: User

Elements whose jquery submission value is not empty

 


Can be used for query

Code:


[Javascript]
// 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;
});

// 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.


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.