我有一个网页,以表格/表格的形式返回搜索结果.我想有一个全选复选框,可以选择搜索结果的所有复选框.我的显示结果代码如下:
<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! (编辑:北几岛)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|