<html>
<head>
<title></title>
<script language="javascript" src="jquery-1.2.6.pack.js"></script>
<script>
$(function(){
$(":button").each(function(i){
$(this).bind("click",function(){
$(":checkbox").each(function(){
if(i==0)
{
$(this).attr("checked",true);
}
else if(i==1)
{
$(this).attr("checked",false);
}
else if(i==2)
{
if($(this).attr("checked"))
{
$(this).attr("checked",false);
}
else
{
$(this).attr("checked",true);
}
}
});
});
});
});
function getValue()
{
var result = "";
$(":checkbox").each(function(){
if($(this).attr("checked"))
{
result += $(this).attr("value");
}
});
alert("您选择的内容有:"+result);
}
</script>
</head>
<body>
<h3>用jquery实现对checkbox的"全选","全不选","反选","获取选中的checkbox值"的功能,如果有什么问题需要探讨,请联系QQ:374053113</h3>
<b>请选中您的乐趣:</b><br />
<input type="checkbox" value="吃"/>吃
<input type="checkbox" value="喝"/>喝
<input type="checkbox" value="玩"/>玩
<input type="checkbox" value="乐"/>乐
<br />
<input type="button" value="全选" />
<input type="button" value="全不选" />
<input type="button" value="反选" />
<input type="button" value="获取选中的值" onclick="getValue()" />
</body>
</html>
- 1
- 2
- 3
前往页