欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

簡單實現(xiàn)jQuery多選框功能

 更新時間:2017年01月09日 14:58:27   作者:Zerone1993  
這篇文章主要為大家詳細介紹了如何簡單實現(xiàn)jQuery多選框功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下

Jquery多選框的基本操作:支持全選、反選、取消全選的功能

HTML正文:

<input type="checkbox" id="c1">全選/全不選<br>
興趣愛好:<br>
<input type="checkbox" name="interst" value="basketball">籃球
<input type="checkbox" name="interst" value="football">足球
<input type="checkbox" name="interst" value="bedminton">羽毛球<br>
<input type="button" id="b1" value="全選">
<input type="button" id="b2" value="全不選">
<input type="button" id="b3" value="反選">
<input type="button" id="b4" value="顯示">

Javascript操作代碼:

$("#c1").click(function(){
if(this.checked){
  $("input[name='interst']").attr("checked","checked");
}else{
  //$("input[name='interst']").attr("checked",""); //等價于
  $("input[name='interst']").removeAttr("checked");
}
});

$("#b1").click(function(){
  $("input[name='interst']").attr("checked","checked");
});

$("#b2").click(function(){
  $("input[name='interst']").attr("checked","");
});

$("#b3").click(function(){
  $("input[name='interst']").each(function(){
  if(this.checked){
    this.checked="";
  }else{
    this.checked="checked";
  }
  });
});

$("#b4").click(function(){
$("input[name='interst']:checked").each(function(){
  alert(this.value);
});
});

效果:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論