Jquery 当禁用和检查道具时,为什么选中和禁用道具返回false?

Jquery 当禁用和检查道具时,为什么选中和禁用道具返回false?,jquery,checkbox,checkboxlist,Jquery,Checkbox,Checkboxlist,这是我的函数A的脚本用于检索复选框的属性,这是它给我错误状态的地方: var checkedCount = 0; $('input.new-checkbox').each(function() { console.log('checked : ' + $(this).prop('checked')); // returned false console.log('disabled : ' + $(this).prop('disabled')); // returned f

这是我的函数A的脚本用于检索复选框的属性,这是它给我错误状态的地方:

var checkedCount = 0;

$('input.new-checkbox').each(function() {

     console.log('checked : ' + $(this).prop('checked')); // returned false
     console.log('disabled : ' + $(this).prop('disabled')); // returned false

     console.log('checked : ' + this.checked); // returned false
     console.log('disabled : ' + $(this).attr('disabled')); // returned undefined

     console.log('checked : ' + $(this).is(':checked')); // returned false

     console.log('disabled : ' + $(this).attr('disabled')); // returned undefined            
     console.log('checked : ' + $(this).attr('checked')); // returned undefined

     if($(this).prop('checked') == true)
     {
            checkedCount = checkedCount + 1;                    
     }

});
下面是函数B的脚本我如何禁用并选中复选框,其中arrayA是一个数组:

$('input.new-checkbox').each(function() {

        for(var i=0; i<arrayA.length; i++)
        {                               
            if($(this).val() == arrayA[i])
            {           
                // set the checkbox checked
                $(this).prop('checked', true);

                // disable the checkbox
                $(this).prop('disabled', true);

            }                               

        }

    });
$('input.new checkbox')。每个(函数(){

对于(var i=0;i使用
attr
而不是
prop
尝试以下操作

            // set the checkbox checked
            $(this).attr('checked', true);

            // disable the checkbox
            $(this).attr('disabled', true);

它在哪里给您提供了错误的状态?您是否在选中后调用第一个代码块?是的,我在第二个函数后调用第一个函数。因此,当这些复选框未被第二个函数禁用或选中时,第一个函数在我自己“单击”/“检查”复选框时(不是通过脚本)给我提供了正确的状态。但在脚本“禁用”和“检查”后,第一个函数给了我错误的状态。这对我来说很好@artm,是的,它对我来说也可以在JSFIDLE上工作,但总体而言,它在我的网站上不完全工作……但不知怎的,它在跨浏览器中也不工作……当它在chrome中时,“检查”变成“未检查”,似乎没有触发change事件的复选框。尝试但没有运气。我实际上已经尝试了所有属性,is(“:checked”),等等。但是真的没有运气。(我尝试了,是的,它确实在html中给我“checked”=“checked”和“disabled”=“disabled”,但道具(“checked”)和道具(“disabled”)仍然为false。