您的位置:首页 > Web前端 > JQuery

Jquery实现复选框只能单选

2014-07-26 09:04 344 查看
<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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: