Disable all check boxes inside a table with jquery

前端 未结 7 1411
北海茫月
北海茫月 2021-01-04 11:09

I need to disable all the check boxes inside a table cell when clicking on a hyperlink inside the same table.

I\'m using the following jquery code to select all the

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 11:51

    Your code can be a lot simpler:

    $el = $(this).parents('table:eq(0)')[0].children('input[type="checkbox"]');
    

    Could be:

    $el = $(this).parents('table:first :checkbox');
    

    Then to disable them:

    $el.attr('disabled', 'disabled');
    

    or to check them:

    $el.attr('checked', 'checked');
    

    or to uncheck them:

    $el.removeAttr('checked');
    

    or to enable them:

    $el.removeAttr('disabled');
    

提交回复
热议问题