jQuery. How to uncheck all checkboxes except one (which was checked)

前端 未结 4 1027
广开言路
广开言路 2021-02-07 03:57

I have html items, 4 example:

Checkbox
4条回答
  •  温柔的废话
    2021-02-07 04:53

    Maybe this will help you:

    .siblings("input[type='checkbox']").attr("checked", true); 
    

    will select all the checkboxes except for the one that was clicked.

    $("input[type=checkbox]").on("click", function() {
    
      if ($(this).val() == "none") {
        
        $(this).siblings("input[type=checkbox]").attr('checked', false);
        
      } else {
        
        $(this).siblings("input[value=none]").attr('checked', false);
    
      }
    });
    
    






提交回复
热议问题