Home > Web Front-end > JS Tutorial > body text

jquery submit element whose value is not empty sample code_jquery

WBOY
Release: 2016-05-16 17:34:05
Original
1027 people have browsed it

When jquery submits elements whose value is not empty,
can be used for querying using
specific code :

Copy code The code is as follows:

//When executing the query, if the form field is empty, it will not be 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 should be returned. The submit method of the form takes a bool value. If it does not return one by default, it will be void
Principle: When the form is submitted, it is based on the name attribute of the element. Yes, as long as the name attribute is not added, it will not be submitted.
The first step is to find all elements, that is, *, and then determine whether the name attribute is not null or empty.
After getting the element, then remove the name attribute if the value is empty.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template