成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? jquery實現全選、反選、獲得所有選中的checkbox
全站頭部文字 我要出現在這里
jquery實現全選、反選、獲得所有選中的checkbox 641 2024-03-18   

舉了7個不同的checkbox狀態,和大家一一分享。

1、全選

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

2、取消全選(全不選)

$("#btn2").click(function(){ 
$("input[name='checkbox']").removeAttr("checked"); 
}) 

3、選中所有奇數

$("#btn3").click(function(){ 
$("input[name='checkbox']:odd").attr("checked","true"); 
}) 

4、選中所有偶數

$("#btn6").click(function(){ 
$("input[name='checkbox']:even").attr("checked","true"); 
}) 

5、反選

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

或者

$("#invert").click(function(){
  $("#ruleMessage [name='delModuleID']:checkbox").each(function(i,o){
   $(o).attr("checked",!$(o).attr("checked"));
  });
 });

6、獲取選擇項的值

var aa=""; 
$("#btn5").click(function(){ 
$("input[name='checkbox']:checkbox:checked").each(function(){ 
aa+=$(this).val() 
}) 
document.write(aa); 
}) 
}) 

7、遍歷選中項

$("input[type=checkbox][checked]").each(function(){
 //由于復選框一般選中的是多個,所以可以循環輸出 
 alert($(this).val()); 
}); 

下面實例講述了jquery實現全選、反選、獲得所有選中的checkbox。分享給大家供大家參考。具體如下:
運行效果截圖如下:

查看圖片

具體代碼如下:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title>無標題頁</title> 
<script src="http://www.gimoo.net/t/1904/js/jquery-1.6.min.js" type="text/javascript"></script> 
<script type="text/javascript"> 
jQuery(function($){ 
//全選 
$("#btn1").click(function(){ 
$("input[name='checkbox']").attr("checked","true"); 
}) 
//取消全選 
$("#btn2").click(function(){ 
$("input[name='checkbox']").removeAttr("checked"); 
}) 
//選中所有基數 
$("#btn3").click(function(){ 
$("input[name='checkbox']:even").attr("checked","true"); 
}) 
//選中所有偶數 
$("#btn6").click(function(){ 
$("input[name='checkbox']:odd").attr("checked","true"); 
}) 
//反選 
$("#btn4").click(function(){ 
$("input[name='checkbox']").each(function(){ 
if($(this).attr("checked")) 
{ 
$(this).removeAttr("checked"); 
} 
else 
{ 
$(this).attr("checked","true"); 
} 
}) 
}) 
//或許選擇項的值 
var aa=""; 
$("#btn5").click(function(){ 
$("input[name='checkbox']:checkbox:checked").each(function(){ 
aa+=$(this).val() 
}) 
document.write(aa); 
}) 
}) 
</script> 
</head> 
<body> 
<form id="form1" runat="server"> 
<div> 
<input type="button" id="btn1" value="全選"> 
<input type="button" id="btn2" value="取消全選"> 
<input type="button" id="btn3" value="選中所有奇數"> 
<input type="button" id="btn6" value="選中所有偶數"> 
<input type="button" id="btn4" value="反選"> 
<input type="button" id="btn5" value="獲得選中的所有值"> 
<br> 
<input type="checkbox" name="checkbox" value="checkbox1"> 
checkbox1 
<input type="checkbox" name="checkbox" value="checkbox2"> 
checkbox2 
<input type="checkbox" name="checkbox" value="checkbox3"> 
checkbox3 
<input type="checkbox" name="checkbox" value="checkbox4"> 
checkbox4 
<input type="checkbox" name="checkbox" value="checkbox5"> 
checkbox5 
<input type="checkbox" name="checkbox" value="checkbox6"> 
checkbox6 
<input type="checkbox" name="checkbox" value="checkbox7"> 
checkbox7 
<input type="checkbox" name="checkbox" value="checkbox8"> 
checkbox8 
</div> 
</form> 
</body> 
</html>

以上就是關于jquery中checkbox使用方法簡單實例演示,希望對大家的學習有所幫助。



主站蜘蛛池模板: 果戈里起点女的被劫走是多少分钟| 玉林电视台| 哈尔移动的城堡 在线观看| 还未入团思想汇报800字| 封神第一部| 田成仁个人资料年龄| 疯狂 电影| 上山悠亚| 美丽的坏女人中文字幕| 黄色网址视频免费| 库里高清壁纸| 多田有花与老丈人电影叫什么名字| 铁血使命电视剧演员表| 大学英语精读4课后答案| 羞羞的动漫在线观看| 斗音| 复仇女王 电视剧| 向团组织靠拢的打算| 小柔seeu| 谜证在线观看免费完整版| 孤战迷城电视剧剧情介绍| 青春修炼手册歌词全部| 阴阳界 电影| 茶山情歌伴奏| 情人电影在线观看高清完整版泰剧 | 巨乳娇妻| 电影《忌讳》完整版| 坏种2| 凯丽| 张纪中个人简历| 回响电影| 番金连| 局内人电影完整版| 在线播放你懂| 怂包| 北京 北京 汪峰歌曲| 木偶人| 你是我心中的太阳泰剧| 基础综合英语邱东林电子版答案| 美国电影《超能力》免费观看| 家庭琐事电影|

!?。≌鹃L長期在線接?。?!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103