<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> php点点通-www.phpddt.com</title>
<meta charset="utf-8">
<script src="jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function(){
//是否选择进行判断
$(".btn").click(function(){
if ($("input:checkbox:checked").length == 0)
{
alert('你未选择爱好');
}
});
//进行反选
$(".btn1").click(function(){
$("input[type=checkbox]").each(function(){
if ($(this).attr("checked"))
{
$(this).attr("checked",false);
}else{
$(this).attr("checked",true);
}
});
});
});
</script>
</head>
<body>
爱好:
<input type="checkbox" name="fav[]" value="read">阅读
<input type="checkbox" name="fav[]" value="music">音乐
<input type="checkbox" name="fav[]" value="sport">体育<br />
<input type="button" name="btn" class="btn" value="提交">
<input type="button" name="btn1" class="btn1" value="反选">
</body>
</html>