admin管理员组文章数量:1596327
1. Try adding this
$('input', '#submForm').each(function(){ $(this).val() == "" && $(this).remove(); })
OR
$('input:text[value=""]', '#submForm').remove();
before
var serialized = $('#submForm').serialize()
来源:http://stackoverflow/a/6240625
You cannot use attribute selector for value
as it is a changing property.
2. Use .filter()
$(document).ready(function () { $('#myForm').submit(function () { $(this).find(":input").filter(function () { return $.trim(this.value).length > 0 }).serialize(); alert('JavaScript done'); }); });
Demo: Fiddle
Note: just serializing the input fields does not change in form submission, it can be used only if the form is submitted via ajax.
If you want to do a normal form submission but want to remove the empty fields then use .remove()
$(document).ready(function () { $('#myForm').submit(function () { $(this).find(":input").filter(function () { return $.trim(this.value).length == 0 }).remove(); alert('JavaScript done'); }); });
来源:http://stackoverflow/a/20189110
3. 我个人使用的是:
$('#submForm').find('input').not('[value=""]').serialize();
OR
$('#search').find('input, select').not('[value=""], [value="0"], [value="DESC"]').serialize();
来源:http://stackoverflow/a/12414286
转自:jQuery 去除表单空值 serialize how to eliminate empty fields
本文标签: 表单SerializejqueryFieldsempty
版权声明:本文标题:jQuery 去除表单空值serialize how to eliminate empty fields 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1728255971a1151017.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论