<html>
<head>
<script type="text/javaScript">
var flage = "";
function tt(t){
divLength = 0;
var divId = t.id;
var radioGroup = document.getElementById(divId);
var inputs = radioGroup.getElementsByTagName('input');
for (var i=0; i < inputs.length; i++){
if (inputs[i].checked){
flage = inputs[i].value;
break;
}
}
}
function aaa(){
if (flage ==""){
alert("请选择");
}
}
</script>
</head>
<body>
<form action="#" name="myform" onsubmit="">
<div id="mydiv1" onclick="tt(this)">
<input type="radio" name="myradio1" value='1'>测试1<br>
<input type="radio" name="myradio1" value='1'>测试2<br>
<input type="radio" name="myradio1" value='1'>测试3<br>
<input type="radio" name="myradio1" value='1'>测试4<br>
<input type="radio" name="myradio1" value='1'>测试5<br>
</div><br>
<div id="mydiv2" onclick="tt(this)">
<input type="radio" name="myradio2" value='1'>测试7<br>
<input type="radio" name="myradio2" value='1'>测试8<br>
<input type="radio" name="myradio2" value='1'>测试9<br>
<input type="radio" name="myradio2" value='1'>测试10<br>
</div>
<br>
<div id="mydiv3" onclick="tt(this)">
<input type="radio" name="myradio3" value='1'>测试13<br>
<input type="radio" name="myradio3" value='1'>测试14<br>
<input type="radio" name="myradio3" value='1'>测试15<br>
<input type="radio" name="myradio3" value='1'>测试16<br>
<input type="radio" name="myradio3" value='1'>测试17<br>
<input type="radio" name="myradio3" value='1'>测试18<br>
</div> <br>
<br>
<br>
<input type="button" value="测试" onclick="aaa()">
</form>
</body>
</html>
大家看看这个代码:
上面的 单选按钮 是动态生成的
我想要的结果是:对他们的选择进行验证,页面的每一组必须有一个选上的