jQuery - 禁用复选框&点击添加属性

时间:2016-04-19 15:19:04

标签: javascript jquery html checkbox

我需要复选框+表行,这些行共享属性,一旦勾选了第一个复选框,就会启用。 (id表格行+ class表示复选框。“

这只是工作的一半

我的问题是,如果您选择了多个复选框并取消选中一个复选框,则所有复选框和表格行都会丢失disabled属性。

https://jsfiddle.net/a1p7an7o/

HTML

            <tr id="IN-HOUSE">
                <input onchange="check();" class="IN-HOUSE" name="bill[]" type="checkbox">
            <label for="Bill?">Bill?</label>
            </td>
        </tr>

的Javascript

<script>
    function check(){
$('input[name*=bill]').change(function() {
   $t = $(this);
   var $th = $(this).attr('class');
      $c = $("tr[id!='"+$th+"']");

   if ($(this).is(':checked')) {

     $('input[name*=bill]').each(function() {
       if ($(this).attr('class') != $th) {
         $(this).not($t).prop('disabled', true);
        $c.not($t).addClass( "disable" );

       }
     });
   } else {
     $('input[name*=bill]').each(function() {

       if ($(this).attr('class') != $th) {
         $(this).not($t).prop('disabled', false);
         $("tr[id!='"+$th+"']").removeClass("disable");

       }
     });
   }
 });
    }
    </script>

0 个答案:

没有答案
相关问题