加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 选择所有复选框

发布时间:2020-12-13 16:21:53 所属栏目:PHP教程 来源:网络整理
导读:我有一个网页,以表格/表格的形式返回搜索结果.我想有一个全选复选框,可以选择搜索结果的所有复选框.我的显示结果代码如下: form action="noJavaScript.php" name="theForm" method="post"table style="border: 1px solid black" RULES=ALL FRAME=VSIDESth /
我有一个网页,以表格/表格的形式返回搜索结果.我想有一个全选复选框,可以选择搜索结果的所有复选框.我的显示结果代码如下:

<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!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读