当前位置: 代码迷 >> JavaScript >> radio button的判断有关问题
  详细解决方案

radio button的判断有关问题

热度:149   发布时间:2012-02-20 21:18:23.0
radio button的判断问题
表单中有5组radio 按钮, 选择分别为对和错。
要求5组的选择只有为 对错对错错的时候,才能激活提交按钮。选择错误的话,则无法点击提交按钮。如何实现这样的功能?求教各位高手。谢谢!

------解决方案--------------------
IE测试通过
<html>
<head>
<title>newpage</title>
<script>
function aaa(){
if(r1.checked&&!r2.checked&&r3.checked&&!r4.checked&&!r5.checked){
s.disabled=false;
}
}
</script>
</head>
<body>
<input type=radio name=r1 onpropertychange="aaa()">
<input type=radio name=r2 onpropertychange="aaa()">
<input type=radio name=r3 onpropertychange="aaa()">
<input type=radio name=r4 onpropertychange="aaa()">
<input type=radio name=r5 onpropertychange="aaa()">
<input type=submit name=s disabled value="提交">
</body>
</html>
------解决方案--------------------
<html > 
<head > 
<title >newpage </title > 
<script language="javascript">
var rs = ["T", "F", "T", "F", "F"];
var tips = ["对", "错"];

function func() {
var res = false;
for (var i=1; i<=rs.length; i++) {
var r = document.getElementsByName("radio" + i);
for (var j=0; j<r.length; j++) {
if (r[j].value==rs[i-1] && !r[j].checked) {
document.getElementById("submit1").disabled = true;
return;
}
}
}
document.getElementById("submit1").disabled = false;
}
</script> 
</head > 
<body >
<form name="form1">


<script language="javascript">
for (var i=1; i<=rs.length; i++) {
document.write("<input type=radio name='radio" + i + "' value='T' onclick='func()' />" + tips[0]);
document.write("<input type=radio name='radio" + i + "' value='F' onclick='func()' />" + tips[1] + "<br />");
}
</script>

<!--
<input type=radio name="radio1" value="T" onclick="func()" /> 对
<input type=radio name="radio1" value="F" onclick="func()" /> 错
<br />
<input type=radio name="radio2" value="T" onclick="func()" /> 对
<input type=radio name="radio2" value="F" onclick="func()" /> 错
<br />
<input type=radio name="radio3" value="T" onclick="func()" /> 对
<input type=radio name="radio3" value="F" onclick="func()" /> 错
<br />
<input type=radio name="radio4" value="T" onclick="func()" /> 对
<input type=radio name="radio4" value="F" onclick="func()" /> 错
<br />
<input type=radio name="radio5" value="T" onclick="func()" /> 对
<input type=radio name="radio5" value="F" onclick="func()" /> 错
<br />
-->
<input type=submit name="submit1" id="submit1" disabled value="提交" > 
</form>
</body > 
</html >
------解决方案--------------------
<HTML>
<head> 
</head> 
  相关解决方案