日期:2014-05-16 浏览次数:20469 次
<html>
<body>
<form>
<table border="1">
<tr>
<td><input type="radio" name="i1" value="0">是</td>
<td><input type="radio" name="i1" value="1">否</td>
</tr>
<tr>
<td><input type="radio" name="i2" value="0">是</td>
<td><input type="radio" name="i2" value="1">否</td>
</tr>
<tr>
<td><input type="radio" name="i3" value="0">是</td>
<td><input type="radio" name="i3" value="1">否</td>
</td>
</form>
</body>
</html>
function isCanSubmit(){
var tags = document.forms[0].getElementsByTagName('input');
for(var i = 0,len = tags.length;i<len;i++){
var comp = tags[i];
if(comp.type == 'radio'){
var radio0 = document.getElementsByName(comp.name)[0];
var radio1 =document.getElementsByName(comp.name)[1];
if(radio0.checked != "checked && radio1.checked != "checked"){
return false;
}
}
}
return true;
}
<head>
<title>单选按钮验证示例_by_theforever_csdn_net</title>
<script type="text/javascript" charset="utf-8" src="http://jqueryjs.googlecode.com/files/jquery-1.3.min.js"></script>
<script type="text/javascript">
$(function() {
$('#theforever_csdn').click(function(){
//当每组都只有两个选项的时候。
if($("input[type=radio]:checked").length==$("input[type=radio]").length/2)
$('#theforever__csdn').submit();
});
});
</script>
</head>
<body>
<form id="theforever__csdn">
<table border="1">
<tr>
<td><input type="radio" name="i1" value="0" checked>是</td>
<td><input type="radio" name="i1" value="1">否</td>
</tr>
<tr>
<td><input type="radio" name="i2" value="0">是</td>
<td><input type="radio" name="i2" value="1">否</td>
</tr>
<tr>
<td><input type="radio" name="i3" value="0">是</td>
<td><input type="radio" name="i3" value="1">否</td>
</tr>
<input id="theforever_csdn" type="button" value="提交" />
</form>