jquery验证表单中checkbox是否被训中...
时间:2010-08-06 来源:wcybxzj
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script language="javascript" src="jquery.min.js"></script>
<script>
$(function(){
var num=0;
$("#sub").click(function(){
$("div input[type=checkbox]").each(function() {
if($(this).attr("checked") ==true){
num=num+1;
}
});
if(num==0){
alert('you must check one');
return false;
}
});
});
</script>
</head>
<body>
<form action='1.php' method='post'>
<input name='text'>
<div id='my_div' value='ybx'>
<input type="checkbox" id="quest1" value="roaming">1111
<input type="checkbox" id="quest1" value="roaming">2222
<input type="checkbox" id="quest1" value="roaming">3333
<input id='sub'type='submit' value=' 提交'>
</div>
</body>
</html>