首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

radio 过滤解决办法

2012-05-29 
radio 过滤HTML codeform nameform1 idform1 methodposttable width90%border0 align

radio 过滤

HTML code
<form name='form1' id="form1" method="post"><table width="90%"  border="0" align="center" >    <tr>      <td height="10" style="color:#FF0000 " >显示器:</td>    <td height="10" style="color:#FF0000 ">        <input type="radio" name="6" value="有"  onChange="change()" >有<input type="radio" name="6" value="无" onChange="change()" checked>无<input type="radio" name="6" value="未知"  onChange="change()" >未知</td>    <td height="10" style="color:#000000 " >鼠标:</td>    <td height="10" style="color:#000000 ">        <input type="radio" name="3" value="有"  onChange="change()" >有<input type="radio" name="3" value="无" onChange="change()" checked>无<input type="radio" name="3" value="未知"  onChange="change()" >未知</td></tr><tr>    <td height="10" style="color:#FF0000 " >键盘:</td>    <td height="10" style="color:#FF0000 ">        <input type="radio" name="4" value="有"  onChange="change()" >有<input type="radio" name="4" value="无" onChange="change()" checked>无<input type="radio" name="4" value="未知"  onChange="change()" >未知</td>    <td height="10" style="color:#000000 " >椅子:</td>    <td height="10" style="color:#000000 ">        <input type="radio" name="7" value="有"  onChange="change()" >有<input type="radio" name="7" value="无" onChange="change()" checked>无<input type="radio" name="7" value="未知"  onChange="change()" >未知</td></tr><tr>    <td height="10" style="color:#000000 " >电源:</td>    <td height="10" style="color:#000000 ">        <input type="radio" name="8" value="有"  onChange="change()" >有<input type="radio" name="8" value="无" onChange="change()" checked>无<input type="radio" name="8" value="未知"  onChange="change()" >未知</td>    <td height="10" style="color:#000000 " >鼻息肉:</td>    <td height="10" style="color:#000000 ">        <input type="radio" name="9" value="有"  onChange="change()" >有<input type="radio" name="9" value="无" onChange="change()" checked>无<input type="radio" name="9" value="未知"  onChange="change()" >未知</td></tr><tr>    <td height="10" style="color:#FF0000 " >网络:</td>    <td height="10" style="color:#FF0000 ">        <input type="radio" name="10" value="有"  onChange="change()" >有<input type="radio" name="10" value="无" onChange="change()" checked>无<input type="radio" name="10" value="未知"  onChange="change()" >未知</td></tr><tr><td height="40" colspan="4"  align="center"><br>    <input name="test" type="button"  id="btn"  value="下一步"  onclick="test();" >     <input name="close" type="reset"  value="重新输入"  id="btn">   </td> </tr></table></form> 


JScript code
<script type="text/javascript">    function test() {        var ar_text = [], ar_radio = [], i = 0;        var obj = document.getElementsByTagName("input"); //貌似是这行有问题        for (var i = 0; i < obj.length; i ++) {            if (obj[i].type == 'radio' && obj[i].value =='有')            {                ar_radio.push(obj[i].value);                }                        }        alert(ar_radio);    }</script>


[解决办法]
HTML code
<form name='form1' id="form1" method="post"><table width="90%"  border="0" align="center" >    <tr>      <td height="10" style="color:#FF0000 " >显示器:</td>    <td height="10" style="color:#FF0000 ">        <input type="radio" name="6" value="有"  onChange="change()" >有<input type="radio" name="6" value="无" onChange="change()" checked>无<input type="radio" name="6" value="未知"  onChange="change()" >未知</td>    <td height="10" style="color:#000000 " >鼠标:</td>    <td height="10" style="color:#000000 ">        <input type="radio" name="3" value="有"  onChange="change()" >有<input type="radio" name="3" value="无" onChange="change()" checked>无<input type="radio" name="3" value="未知"  onChange="change()" >未知</td></tr><tr>    <td height="10" style="color:#FF0000 " >键盘:</td>    <td height="10" style="color:#FF0000 ">        <input type="radio" name="4" value="有"  onChange="change()" >有<input type="radio" name="4" value="无" onChange="change()" checked>无<input type="radio" name="4" value="未知"  onChange="change()" >未知</td>    <td height="10" style="color:#000000 " >椅子:</td>    <td height="10" style="color:#000000 ">        <input type="radio" name="7" value="有"  onChange="change()" >有<input type="radio" name="7" value="无" onChange="change()" checked>无<input type="radio" name="7" value="未知"  onChange="change()" >未知</td></tr><tr>    <td height="10" style="color:#000000 " >电源:</td>    <td height="10" style="color:#000000 ">        <input type="radio" name="8" value="有"  onChange="change()" >有<input type="radio" name="8" value="无" onChange="change()" checked>无<input type="radio" name="8" value="未知"  onChange="change()" >未知</td>    <td height="10" style="color:#000000 " >鼻息肉:</td>    <td height="10" style="color:#000000 ">        <input type="radio" name="9" value="有"  onChange="change()" >有<input type="radio" name="9" value="无" onChange="change()" checked>无<input type="radio" name="9" value="未知"  onChange="change()" >未知</td></tr><tr>    <td height="10" style="color:#FF0000 " >网络:</td>    <td height="10" style="color:#FF0000 ">        <input type="radio" name="10" value="有"  onChange="change()" >有<input type="radio" name="10" value="无" onChange="change()" checked>无<input type="radio" name="10" value="未知"  onChange="change()" >未知</td></tr><tr><td height="40" colspan="4"  align="center"><br>    <input name="test" type="button"  id="btn"  value="下一步"  onclick="fn()" >     <input name="close" type="reset"  value="重新输入"  id="btn">   </td> </tr></table></form><script type="text/javascript">    function fn(){        var ar_text = [], ar_radio = [], i = 0;        var obj = document.getElementsByTagName("input"); //貌似是这行有问题        for (var i = 0; i < obj.length; i ++) {            console.log( obj[i].value )            if (obj[i].type == 'radio' && obj[i].value =='有' && obj[i].checked)            {                ar_radio.push(obj[i].value);                }                        }        alert(ar_radio);    }</script> 

热点排行
Bad Request.