php – 选择所有复选框

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 选择所有复选框脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个网页,以表格/表格的形式返回搜索结果.我想有一个全选复选框,可以选择搜索结果的所有复选框.我的显示结果代码如下:

<form action="noJavaScript.PHP" name="theForm" method="post">
<table style="border: 1px solid black" RULES=ALL FRAME=VSIDES>
<th> </th><th>Order #</th><th>InsPEctor</th><th>Reference #</th><th>Client Name</th><th>PRoperty Address</th><th>CITy</th><th>state</th><th>Zip</th><th>inspection Date</th>
        <?PHP
            while ($row = MysqL_fetch_assoc($result))
            {
                echo '<tr><td>';
                echo '<input type="checkBox" name="selected[]" value="'.$row['order_number'].'"/>';
                echo '</td>';
                foreach ($row as $key => $value)
                    echo '<td>'.htMLspecialchars($value).'</td>';
                echo '</tr>';
            }
        ?>

    </table>
<input type="submit" name="submit" value="Edit/Modify Order" onClick="document.theForm.action='modify.PHP'">
<input type="submit" name="submit" value="Clone Order" onClick="document.theForm.action='clone.PHP'">
<input type="submit" name="submit" value="Delete Order" onClick="document.theForm.action='deleteorder.PHP'">
<input type="submit" name="submit" value="Archive Order" onClick="document.theForm.action='archive.PHP'">

</form>

我试过使用以下功能

<script type="text/javascript"
<!--
function SetAllCheckBoxes(FormName,FieldName,CheckValue)
{
    if(!document.forms[FormName])
        return;
    VAR objCheckBoxes = document.forms[FormName].elements[FieldName];
    if(!objCheckBoxes)
        return;
    var countCheckBoxes = objCheckBoxes.length;
    if(!countCheckBoxes)
        objCheckBoxes.checked = CheckValue;
    else
        // set the check value for all check Boxes
        for(var i = 0; i < countCheckBoxes; i++)
            objCheckBoxes[i].checked = CheckValue;
}
// -->
</script>

这样的按钮:

<input type="button" onclick="SetAllCheckBoxes('theForm','myCheckBox',true);" value="Check All">;

但我无法让它发挥作用.

解决方法

为每个复选框输入添加一个类.

echo’< input type =“checkBox”name =“selected []”value =“'.$row ['order_number'].'”class =“yourclass”/>‘;

然后在javascript中迭代文档中的所有输入字段,并检查它们是否同时具有type =“checkBox”和class =“yourclass”.并将所有这些设置为CHECKED!

脚本宝典总结

以上是脚本宝典为你收集整理的php – 选择所有复选框全部内容,希望文章能够帮你解决php – 选择所有复选框所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。