前端多选框实现单选操作

html:

<input type="checkbox" name="receivedGoods" value="0" class="checkBoxInput" >Entirely
<input type="checkbox" name="receivedGoods" value="1" class="checkBoxInput" >Partially

js:

$(function(){
  $('input[type="checkbox"]').each(function(){
      $(this).click(function(){
        if($(this).attr('checked')){
            $('[type="checkbox"][name="'+$(this).attr("name")+'"]').removeAttr('checked');
            $(this).attr('checked','checked');
        }
      });
    });
});

猜你喜欢

转载自blog.csdn.net/weixin_43473995/article/details/88738649