21,891
社区成员
发帖
与我相关
我的任务
分享
<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=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>
//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>";
}
?>
<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>
$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>";
}