Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 禁用包含不同属性的复选框_Javascript_Jquery_Checkbox - Fatal编程技术网

Javascript 禁用包含不同属性的复选框

Javascript 禁用包含不同属性的复选框,javascript,jquery,checkbox,Javascript,Jquery,Checkbox,我试图禁用选中仓库后具有不同仓库位置的复选框。例如,如果我选中California,我想禁用来自其他州的所有复选框。我正试图基于属性whseID来实现这一点,但我不知道如何让jquery对该属性进行区分。有时我会从一个仓库运送多个物品。因此,当我在加利福尼亚州选中1个复选框时,我需要加利福尼亚州的另一个复选框保持启用状态,但我需要华盛顿和亚利桑那州禁用 <table width="50%" border="0" cellspacing="0" cellpadding="0">

我试图禁用选中仓库后具有不同仓库位置的复选框。例如,如果我选中California,我想禁用来自其他州的所有复选框。我正试图基于属性whseID来实现这一点,但我不知道如何让jquery对该属性进行区分。有时我会从一个仓库运送多个物品。因此,当我在加利福尼亚州选中1个复选框时,我需要加利福尼亚州的另一个复选框保持启用状态,但我需要华盛顿和亚利桑那州禁用

<table width="50%" border="0" cellspacing="0" cellpadding="0">
    <tr class="grdnt">
        <th style="color:black;">Checkbox</th>
        <th style="color:black;border-left:1px solid;">Warehouse</th>
        <th style="color:black;border-left:1px solid;">Item</th>
    </tr>
    <tr id="transferDetailCol">
        <td>
            <input type="checkbox" class="tfrCheck" name="tfrCheck[]" whseID="CA" />
        </td>
        <td class="Whse">California</td>
        <td class="Item">J29458</td>
    </tr>
    <tr id="transferDetailCol">
        <td>
            <input type="checkbox" class="tfrCheck" name="tfrCheck[]" whseID="CA" />
        </td>
        <td class="Whse">California</td>
        <td class="Item">J29478</td>
    </tr>
    <tr id="transferDetailCol">
        <td>
            <input type="checkbox" class="tfrCheck" name="tfrCheck[]" whseID="WA" />
        </td>
        <td class="Whse">Washington</td>
        <td class="Item">J29478</td>
    </tr>
    <tr id="transferDetailCol">
        <td>
            <input type="checkbox" class="tfrCheck" name="tfrCheck[]" whseID="AZ" />
        </td>
        <td class="Whse">Arizona</td>
        <td class="Item">J29478</td>
    </tr>
</table>

$(document).on('click', '.tfrCheck', function () {
    var allCheckBox = $(".tfrCheck");
    var count_checked = allCheckBox.filter(":checked").length;
    var whseID = $(this).attr('whseID');
    if (count_checked >= 1) {

        $(".tfrCheck:contains(whseID)").attr('disabled', 'disabled');
        //$(".tfrCheck:not(:checked)").attr('disabled','disabled');

    } else {
        $(".tfrCheck").removeAttr('disabled');
    }
});

复选框
仓库
项目
加利福尼亚
J29458
加利福尼亚
J29478
华盛顿
J29478
亚利桑那州
J29478
$(文档).on('单击','.tfrCheck',函数(){
var allCheckBox=$(“.tfrCheck”);
var count_checked=allCheckBox.filter(“:checked”).length;
var whseID=$(this.attr('whseID');
如果(已检查计数>=1){
$(“.tfrCheck:contains(whseID)”).attr('disabled','disabled');
//$(“.tfrCheck:not(:checked)”).attr('disabled','disabled');
}否则{
$(“.tfrCheck”).removeAttr('disabled');
}
});

尝试使用以下行:

$('.tfrCheck:not([whseID='+ whseID +'])').attr('disabled', 'disabled');
尝试使用以下行:

$('.tfrCheck:not([whseID='+ whseID +'])').attr('disabled', 'disabled');

Ragnar的答案很接近,但由于您希望禁用其他状态,请使用

$('.tfrCheck:not([whseID='+ whseID +'])').attr('disabled', 'disabled');

Ragnar的答案很接近,但由于您希望禁用其他状态,请使用

$('.tfrCheck:not([whseID='+ whseID +'])').attr('disabled', 'disabled');
“属性不等于选择器”应有助于:

allCheckBox.filter('[whseID!='+whseID+''']').attr('disabled',true);

属性不相等选择器”应有助于:

allCheckBox.filter('[whseID!='+whseID+''']').attr('disabled',true);

代码>=应该是
==
应该是
=我相信。