码迷,mamicode.com
首页 > Web开发 > 详细

Jquery实现复选框只能单选

时间:2014-07-27 12:11:06      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:jquery   复选框   checkbox   单选   

<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
</head>
<body>
<div id="divckb">
<input type="checkbox" name="ckb1" value="1" />张三
<input type="checkbox" name="ckb2" value="2" />李四
<input type="checkbox" name="ckb3" value="3"/>王五
<input type="checkbox" name="ckb4" value="4" />赵六
</div>
<script>
$(function(){

$("#divckb input").each(function(){
									
	$(this).change(function(){
						  
		var test= $(this).attr("checked"); 
	
		if($(this).attr("checked")){
		        //此处写你的处理
			//$("#divckb input").each(function(){
			//	//alert($(this).val());								//							  
			//	if(test== $(this).attr("checked")){		  
			//		$(this).attr("checked",false);
			//		//alert($(this).val()+"-1");
			//	}else{
			//		$(this).attr("checked",false);
			//		//alert($(this).val()+"-2");
			//	}
			//}); 
    		}
		else{
			$(this).attr("checked",true);
			$(this).siblings().each(function(){
				$(this).attr("checked",false);
			});
			//此处写你的处理
		}
	
	});
   
});
});
</script>
</body>
</html>


本文出自 “KangSafe” 博客,请务必保留此出处http://kangsafe.blog.51cto.com/5686165/1530339

Jquery实现复选框只能单选

标签:jquery   复选框   checkbox   单选   

原文地址:http://kangsafe.blog.51cto.com/5686165/1530339

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!