//ch.html
<html>
<body>
<form action="getchk.php" method="post">
<table>
<tr><td><input type="checkbox" name="chk[]" value="a">1</td></tr>
<tr><td><input type="checkbox" name="chk[]" value="b">2</td></tr>
<tr><td><input type="checkbox" name="chk[]" value="c">3</td></tr>
<tr><td><input type="button" value="全选"></td></tr>
</table>
<input type="submit" value="Submit">
</form>
</body>
</html>//getchk.php
<?php
$p_chk=$_POST["chk"];echo "Count Checkbox : ".count($p_chk)."<br>";
echo "Their values are : <br>";
for($i=0;$i<count($p_chk);$i++)
{
echo $p_chk[$i]."<br>";
}
?>上面有二个文件,现全选没实现,我点ch.html中的全选时,三个checkbox要全选中,
并点提交时,要把三个checkbox的值传入到 php页面中去,怎么实现呀,
<html>
<body>
<form action="getchk.php" method="post">
<table>
<tr><td><input type="checkbox" name="chk[]" value="a">1</td></tr>
<tr><td><input type="checkbox" name="chk[]" value="b">2</td></tr>
<tr><td><input type="checkbox" name="chk[]" value="c">3</td></tr>
<tr><td><input type="button" value="全选"></td></tr>
</table>
<input type="submit" value="Submit">
</form>
</body>
</html>//getchk.php
<?php
$p_chk=$_POST["chk"];echo "Count Checkbox : ".count($p_chk)."<br>";
echo "Their values are : <br>";
for($i=0;$i<count($p_chk);$i++)
{
echo $p_chk[$i]."<br>";
}
?>上面有二个文件,现全选没实现,我点ch.html中的全选时,三个checkbox要全选中,
并点提交时,要把三个checkbox的值传入到 php页面中去,怎么实现呀,
<html>
<script language="javascript" type="text/javascript">
//全选
function SelectAllCheckboxes(spanChk)
{
var xState=spanChk.checked;
//alert(xState); elm = spanChk.form.elements;
//alert(elm.length);
for(i = 0; i < elm.length-1; i++)
{
if(elm[i].type == "checkbox" && elm[i].id != spanChk.id)
{
if(elm[i].checked!=xState)
elm[i].click();
}
}
}
</script><body>
<form action="getchk.php" method="post">
<table>
<tr> <td> <input type="checkbox" name="chk[]" value="a">1 </td> </tr>
<tr> <td> <input type="checkbox" name="chk[]" value="b">2 </td> </tr>
<tr> <td> <input type="checkbox" name="chk[]" value="c">3 </td> </tr>
<tr> <td> <input type="button" value="全选"> </td> </tr>
</table>
<input name="allselect" type="checkbox" id="allselect" onclick="SelectAllCheckboxes(allselect)" />全选<input type="submit" value="Submit">
</form>
</body>
</html> PHP就用你的不用改$p_chk=$_POST["chk"];
echo "Count Checkbox : ".count($p_chk)." <br>";
echo "Their values are : <br>";
for($i=0;$i <count($p_chk);$i++)
{
echo $p_chk[$i]." <br>";
}
//ch.html
<script language="javascript">
function selectAll()
{
var CheckBoxList = document.getElementsByTagName('INPUT');
for(var i=0;i<CheckBoxList.length;i++)
{
if(CheckBoxList[i].type == 'checkbox')
o[i].checked=true;
}
}
</script><html>
<body>
<form action="getchk.php" method="post">
<table>
<tr> <td> <input type="checkbox" name="chk[]" value="a">1 </td> </tr>
<tr> <td> <input type="checkbox" name="chk[]" value="b">2 </td> </tr>
<tr> <td> <input type="checkbox" name="chk[]" value="c">3 </td> </tr>
<tr> <td> <input type="button" value="全选" onclick ="selectAll()"> </td> </tr>
</table>
<input type="submit" value="Submit">
</form>
</body>
</html>
<?php
foreach($_POST['chk'] as $c){
echo $c."<br>";
}
?>
[code=JScript]<script language="javascript">
function selectAll()
{
var CheckBoxList = document.getElementsByTagName('input');
for(var i=0;i<CheckBoxList.length;i++)
{
if(CheckBoxList[i].type == 'checkbox')
CheckBoxList[i].checked=true;
}
}
</script><html>
<body>
<form action="getchk.php" method="post">
<table>
<tr> <td> <input type="checkbox" name="chk[]" value="a">1 </td> </tr>
<tr> <td> <input type="checkbox" name="chk[]" value="b">2 </td> </tr>
<tr> <td> <input type="checkbox" name="chk[]" value="c">3 </td> </tr>
<tr> <td> <input type="button" value="全选" onclick ="selectAll()"> </td> </tr>
</table>
<input type="submit" value="Submit">
</form>
</body>
</html>
[/code]
function selectAll()
{
var CheckBoxList = document.getElementsByTagName('input');
for(var i=0;i<CheckBoxList.length;i++)
{
if(CheckBoxList[i].type == 'checkbox')
CheckBoxList[i].checked=true;
}
}
</script><html>
<body>
<form action="getchk.php" method="post">
<table>
<tr> <td> <input type="checkbox" name="chk[]" value="a">1 </td> </tr>
<tr> <td> <input type="checkbox" name="chk[]" value="b">2 </td> </tr>
<tr> <td> <input type="checkbox" name="chk[]" value="c">3 </td> </tr>
<tr> <td> <input type="button" value="全选" onclick ="selectAll()"> </td> </tr>
</table>
<input type="submit" value="Submit">
</form>
</body>
</html>
<input name="articleDel[]"
id="articleDel[]" type="checkbox" value="" onClick="selAll(this)">
function selAll(e)
{
var a = document.getElementsByName('articleDel[]');
var l = a.length;
while(l--)
a[l].checked=e.checked;
}