禁用复选框,并使用jQuery取消选中它 [英] Disabling check box and uncheck it using jQuery

查看:175
本文介绍了禁用复选框,并使用jQuery取消选中它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我在for循环中动态生成td元素。

In below code I am dynamically generating td elements in for loop.

jQuery("#dialog_load_content").load(url, function() {
        var clientName = jQuery('#client option:selected').text();
        var clientId = Number(jQuery('#client option').filter(function() {return jQuery(this).html() == clientName;}).val());
        var navDate = jQuery('input:checkbox:checked.signOff').closest('tr').find('td:eq(2)').html();
        var fundName = jQuery('input:checkbox:checked.signOff').closest('tr').find('td:eq(0)').html();
        var fundId = Number(jQuery('#fund option').filter(function() {return jQuery(this).html() == fundName;}).val());
        jQuery.post('getNavPackReportsStatus', {clientId: clientId, fundId: fundId, periodEndDate: navDate}, function(data) {
            var reports = data;

            for(var count = 0; count< reports.length; count++) {
                jQuery('#wrkbkRptTable tbody').append('<tr>' +
                        '<td><input type="checkbox" id="'+reports[count].reportStoreId+'" name="'+reports[count].reportName+'" checked/></td>'+
                        '<td>' + (count + 1) + '</td>'+
                        '<td>' + reports[count].reportGroupDisplayName + '</td>'+
                        '<td>' + reports[count].reportName + '</td>'+
                        '<td id="chkReportID">' + ((reports[count].reportStoreId == null || reports[count].reportStoreId == '') ? '<font color="red">Not Available</font>' : '<font color="green">Available</font>') + '</td>'+
                        '</tr>');
            }


        });

    });

我试图禁用复选框并取消选中此复选框,但它不工作

I tried to disable check box and uncheck check box using this, but it's not working

 jQuery('#wrkbkRptTable input:checked').each(function() {
     var test=jQuery('#wrkbkRptTable input:checked').attr('id');
    if(test==null || test=='' || test=='undefined')
    {
         alert(test);
         jQuery("#"+test+"").prop( "disabled", true );
    }

});    

我要禁用复选框,并使用第一个td(id属性值)取消选中,如
this:if(id == null then disable& uncheck it)

I want to disable check box and uncheck it using first td (id attribute value) like this: if (id == null then disable & uncheck it)

推荐答案

b
$ b

try something like this

$(document).ready(function() {
     jQuery('#wrkbkRptTable input:checked').each(function() {
        var test = this.id;
        if(test==null || test=='undefined' || test.trim()=='')
        {
             this.checked = false;
             this.disabled = true;
        }
    });
});

这篇关于禁用复选框,并使用jQuery取消选中它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆