JQuery 实现多个checkbox类型input 一次只能选中一个

html:

<input type="checkbox" status="false">一

<input type="checkbox" status="false">二

<input type="checkbox" status="false">三

<input type="checkbox" status="false">四

 

js:

//禁止多选
$("input").on("click",function(){
  if($(this).is(":checked")){
    $(this).attr("status","true");
  }else{
    $(this).attr("status","false");
  }
  let status = $(this).attr("status");
  $("input").each(function(){
    if($(this).attr("status") !== status){
      $(this).attr("disabled","disabled");
    }else{
      $(this).removeAttr("disabled");
    }
  })
})

posted @ 2021-07-17 10:13  追风不跟风  阅读(411)  评论(0)    收藏  举报