<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<form name="formEdit" method="post" >
<table >
<tr>
<td >
1.是否大学生
<input type=radio name="CheckFlag1" value="on"> 是
<input type=radio name="CheckFlag1" value="off">否
</td>
</tr>
<input type="button" value="check" onclick="checkState()" />
</table>
</form>
</BODY>
</HTML>
<script>
function checkState()
{
var objs = document.forms.formEdit.getElementsByTagName("input");
for(var i=0; i<objs.length; i++)
{
if(objs[i].type=='radio' && getRadioValue(objs[i].name)==null)
{
alert("请选择您的答案!");
objs[i].focus();
return false;
}
}
alert("答案将被提交,谢谢您!");
return true;
}function getRadioValue(objName)
{
var objs = document.getElementsByName(objName);
for(var i=0; i<objs.length; i++)
{
if(objs[i].tagName.toLowerCase()=='input' && objs[i].checked) return objs[i].value;
}
return null;
}
</script>http://community.csdn.net/Expert/topic/4126/4126348.xml?temp=.8020746
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<form name="formEdit" method="post" >
<table >
<tr>
<td >
1.是否大学生
<input type=radio name="CheckFlag1" value="on"> 是
<input type=radio name="CheckFlag1" value="off">否
</td>
</tr>
<input type="button" value="check" onclick="checkState()" />
</table>
</form>
</BODY>
</HTML>
<script>
function checkState()
{
var objs = document.forms.formEdit.getElementsByTagName("input");
for(var i=0; i<objs.length; i++)
{
if(objs[i].type=='radio' && getRadioValue(objs[i].name)==null)
{
alert("请选择您的答案!");
objs[i].focus();
return false;
}
}
alert("答案将被提交,谢谢您!");
return true;
}function getRadioValue(objName)
{
var objs = document.getElementsByName(objName);
for(var i=0; i<objs.length; i++)
{
if(objs[i].tagName.toLowerCase()=='input' && objs[i].checked) return objs[i].value;
}
return null;
}
</script>http://community.csdn.net/Expert/topic/4126/4126348.xml?temp=.8020746
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货