首页 > Web开发 > 详细

Jquery实现复选框只能单选

时间:2014-07-27 12:11:07      阅读:218      评论:0      收藏:0      [点我收藏+]
<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实现复选框只能单选

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!