Jquery实现页面上所有的checkbox只能选中一个

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>checkBox4radio.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function () {
var allBox = $(":checkbox");
//var allBox = $("#div input:checkbox");
allBox.click(function () {
allBox.removeAttr("checked");
$(this).attr("checked", "checked");
});
$(":button").click(function () {
alert($(":checkbox:checked").val());
});
});
</script> </head> <body>
<input type="button" value="remove" />
<div>
<input type="checkbox" value="1"/>
<input type="checkbox" value="2"/>
<input type="checkbox" value="3"/>
<input type="checkbox" value="4"/>
</div>
</body>
</html>
上一篇:github中SSH公钥的生成与添加


下一篇:ASP.NET中如何删除最近打开的项目和文件的记录