如何添加特定div来形成查找

时间:2015-07-29 01:12:24

标签: javascript jquery html5 thymeleaf

以下是正常运行的代码。但它找到了整个表格的所有输入。如何在表单中包含/省略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>

1 个答案:

答案 0 :(得分:0)

我更改了以下行:

var atleastOneFilled = checkFields($("#searchForm")); 

作为

var atleastOneFilled = checkFields($("#searchForm #includethisdiv"));