Javascript jquery3对多属性查找给出了错误的答案
我有一个可以在jQuery1.4.3上正常工作的构造,但不适用于jQuery3.1.1。在我的页面中,有许多输入字段如下:Javascript jquery3对多属性查找给出了错误的答案,javascript,jquery,Javascript,Jquery,我有一个可以在jQuery1.4.3上正常工作的构造,但不适用于jQuery3.1.1。在我的页面中,有许多输入字段如下: <input type="text" name="docNo" oninput="setIgnoreDateRange();" data-auto-select-ignoredate="true"> 在使用jQuery 1.4.3的网页中,我会根据有多少字段有值得到答案。如果总共有六个字段,其中一个字段有一个值,则长度为1 在我使用jQuery 3.1.1的网
<input type="text" name="docNo" oninput="setIgnoreDateRange();" data-auto-select-ignoredate="true">
在使用jQuery 1.4.3的网页中,我会根据有多少字段有值得到答案。如果总共有六个字段,其中一个字段有一个值,则长度为1
在我使用jQuery 3.1.1的网页中,我得到了表单上字段数的简单计数,就好像[value!=“”]
根本不存在一样。如果总共有六个字段,其中一个字段中有一个值,则长度为六
在多属性搜索的公式中有什么变化吗?在最近的jQuery版本中,您可以通过其
值
属性选择输入
,但不能通过实际的JavaScript值
属性
现在你必须使用过滤。以下是如何做到这一点:
ES6
被称为[…ignoringInputs]
(参数)=>函数
var ignoringInputs = $('form[name="salesOrderSearchForm"] input[data-auto-select-ignoredate="true"]');
ignoringInputs = ignoringInputs.filter(function () {
return $(this).val() !== '';
}
console.log(ignoringInputs.length);
工作示例(ES6)
document.getElementById('checkButton')。addEventListener('click',()=>{
让ignoringInputs=document.querySelectorAll('form[name=“salesOrderSearchForm”]input[data auto select ignoredate=“true”]);
ignoringInputs=[…ignoringInputs].filter((元素)=>element.value!==“”);
console.log(ignoringInputs.length);
});代码>
。作为控制台包装{/*仅用于输出控制台*/
最高:50%;
}
在jQuery中,它应该是this.value!=''
或$(this).val()!=''
.Corrected and+1Command$(“form[name='saleordersearchForm'])。查找('[data auto select ignoredate=“true”])。筛选(function(){return$(this.val()!='';})。长度;这是为我做的。
let ignoringInputs = document.querySelectorAll('form[name="salesOrderSearchForm"] input[data-auto-select-ignoredate="true"]');
ignoringInputs = [...ignoringInputs].filter((element) => element.value !== '');
console.log(ignoringInputs.length);
var ignoringInputs = $('form[name="salesOrderSearchForm"] input[data-auto-select-ignoredate="true"]');
ignoringInputs = ignoringInputs.filter(function () {
return $(this).val() !== '';
}
console.log(ignoringInputs.length);