以下是正常运行的代码。但它找到了整个表格的所有输入。如何在表单中包含/省略div。
var atleastOneFilled = checkFields($("#searchForm"));
function checkFields(form) {
var checks_radios = form.find(':checkbox, :radio');
var inputs = form.find(':input').not(checks_radios).not('[type="submit"],[type="button"],[type="reset"],[type="hidden"]');
var checked = checks_radios.filter(':checked');
var filled = inputs.filter(function(){
var newvalue = $(this).val();
var newval = $.trim($(this).val());
return $.trim($(this).val()).length > 0;
});
if(checked.length + filled.length === 0) {
return false;
}
else{
return true;}
}
HTML:
<form id="searchForm" action="#" th:object="${person}" method="post">
<div id="includethisdiv">
// Include contents of this div for checking.
</div>
<div id="omitthisdiv">
// Omit this div for checking.
</div>
</form>
答案 0 :(得分:0)
我更改了以下行:
var atleastOneFilled = checkFields($("#searchForm"));
作为
var atleastOneFilled = checkFields($("#searchForm #includethisdiv"));