繁体   English   中英

使用一个单选按钮检查所有其他单选按钮

[英]check all other radio button using one radio button

我在这里获取卷号,在“ php”中有两个单选按钮。卷号会有多个,因此我想使用特定的单选按钮或复选框一次检查所有值为“是”的单选按钮。虽然我没有在代码中写那个按钮,因为我不知道写什么。请给我一个使用Java脚本的解决方案。

while($row=mysqli_fetch_assoc($result))
{

    echo"<tr><td>{$row['roll']}</td>
    </td><td></td><td></td><td></td><td>
    <td><input type='radio' name='present[$i]' value='Yes'>YES</td>
          </td><td></td><td></td><td>
          <td><input type='radio' name='present[$i]' value='No'>NO</td></tr>";
          $i++;

}

这种交互类型应使用Javascript实现,因为它是客户端操作。

HTML:

<form>
    <input type="radio" name="radio1" value="yes"/>Yes
    <input type="radio" name="radio1" value="no"/>No
    <br />
    <input type="radio" name="radio2" value="yes"/>Yes
    <input type="radio" name="radio2" value="no"/>No
    <br />
    <input type="radio" name="radio3" value="yes"/>Yes
    <input type="radio" name="radio3" value="no"/>No
    <br />
    <input type="button" value="Select All" onclick="selectAll('radio',true);"/>
    <input type="button" value="Deselect All" onclick="selectAll('radio',false);"/>
</form>

Javascript:

function selectAll( prefix, set ) {
    var form = document.forms[0], //Get the appropriate form
        i = 0,
        radio;
    while( radio = form[prefix + ++i] ) //Loop through all named radio# elements
        for( var j = 0; j < radio.length; j++ ) //Loop through each set of named radio buttons
            if( radio[j].value == (set ? "yes" : "no") ) //Selector based on value of set
                radio[j].checked = true; //Check that radio button!
}

JSFiddle

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM