jquery commit value is not empty element sample code _jquery

Source: Internet
Author: User
jquery commits an element that is not empty
can be used to query when using the
Specific code :
Copy Code code as follows:

When the query is executed, if the form's fields are empty, they are not committed
$ ("#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 To return only, the form's Submit method takes the bool value, if not the default return one, then is void
principle : When a form is submitted, it is based on the attribute of the element's name, and is not committed as long as the name attribute is not added.
The first step is to find all the elements that are *, and then to determine that the Name property is not NULL or null
The Name property is removed after the element is taken, and the value is empty.

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.