<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb_23-12" />
<title>无标题文档</title>
<script>
function chkRadio(n)
{
var o = document.getElementsByName(n);
for(var i = 0;i < o.length;i++) if(o[i].checked) return true
return false;
}
</script>
</head><body>
<input name="A01" value="FD" type="radio">
<input name="A01" value="ERERER" type="radio">
<input name="A01" value="HGHGHGH" type="radio">
<input type="button" value="检测A01" onclick="alert(chkRadio('A01'))"> <input name="A02" value="FD" type="radio">
<input name="A02" value="ERERER" type="radio">
<input name="A02" value="HGHGHGH" type="radio">
<input type="button" value="检测A02" onclick="alert(chkRadio('A02'))"> </body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb_23-12" />
<title>无标题文档</title>
<script>
function chkRadio(n)
{
var o = document.getElementsByName(n);
for(var i = 0;i < o.length;i++) if(o[i].checked) return true
return false;
}
</script>
</head><body>
<input name="A01" value="FD" type="radio">
<input name="A01" value="ERERER" type="radio">
<input name="A01" value="HGHGHGH" type="radio">
<input type="button" value="检测A01" onclick="alert(chkRadio('A01'))"> <input name="A02" value="FD" type="radio">
<input name="A02" value="ERERER" type="radio">
<input name="A02" value="HGHGHGH" type="radio">
<input type="button" value="检测A02" onclick="alert(chkRadio('A02'))"> </body>
</html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head><body><input name="A01" value="FD" type="radio">
<input name="A01" value="ERERER" type="radio">
<input name="A01" value="HGHGHGH" type="radio">
<input name="A02" value="FD" type="radio">
<input name="A02" value="ERERER" type="radio">
<input name="A02" value="HGHGHGH" type="radio"> <input type=button value="Check Radio" onclick="javascript:checkRadio()" />
<script language=javascript> function checkRadio()
{
var result = false;
var arrA01 = document.getElementsByName( "A01" );
for( var i=0; i<arrA01.length; i++ )
{
if( arrA01[i].checked )
{
result = true;
break;
}
}
if( !result )
{
var arrA02 = document.getElementsByName( "A02" );
for( var i=0; i<arrA02.length; i++ )
{
if( arrA02[i].checked )
{
result = true;
break;
}
}
}
alert( result );
}</script>
</body></html>
两组都选择返回TRUE,只有一个选择也返回FALSE
只用一个onclick="alert(chkRadio('A01'))" 事件
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb_23-12" />
<title>无标题文档</title>
<script>
function chkRadio(n)
{//检查一项
var o = document.getElementsByName(n);
for(var i = 0;i < o.length;i++) if(o[i].checked) return true
return false;
}function withTow()
{//合并两项
alert(chkRadio("A01") && chkRadio("A02"));
}
</script>
</head><body>
<input name="A01" value="FD" type="radio">
<input name="A01" value="ERERER" type="radio">
<input name="A01" value="HGHGHGH" type="radio">
<input type="button" value="检测A01" onclick="alert(chkRadio('A01'))"> <input name="A02" value="FD" type="radio">
<input name="A02" value="ERERER" type="radio">
<input name="A02" value="HGHGHGH" type="radio">
<input type="button" value="检测A02" onclick="alert(chkRadio('A02'))"> <br><br><input type="button" value="检测两项" onclick="withTow()"> </body>
</html>