26 2012年10月

checkbox全选及提交到PHP

发布于:16时51分 | 来源:湛蓝天空  |   编辑:湛蓝  |   日志分类:JavaScript  |   已聚集:人围观
html代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>checkbox全选及提交到PHP</title>
<script type="text/javascript" language="javascript">
function chkAll_onClick(){
if(typeof(document.del.chkItem)=="undefined") return;
if (typeof(document.del.chkItem[0]) == "undefined"){document.del.chkItem.checked = document.del.chkAll.checked;}
else
for (i = 0; i <document.del.chkItem.length; i++)
document.del.chkItem[i].checked = document.del.chkAll.checked
return;
}
</script>
</head>
<body>

<script type="text/javascript">
function check_all(obj,cName)
{
    var checkboxs = document.getElementsByName(cName);
    for(var i=0;i<checkboxs.length;i++){checkboxs[i].checked = obj.checked;}
}
</script>

<form id="form1" name="form1" method="post" action="getbox.php">
<table width="100%">

  <tr>
     <td><input type="checkbox" name="checkbox[]" value="a" />甲类 <input type="checkbox" name="checkbox[]" value="b" />乙类 <input type="checkbox" name="checkbox[]" value="c" />丙类</td>
  </tr>

  <tr>
     <td><input type="checkbox" name="pointall" onclick="check_all(this,'checkbox[]')" />全选/取消</td>
  </tr>
  <tr>
     <td><input type="submit" name="Submit" value="提交" /></td>
  </tr>
 </table>
 </form>
</body>
</html>

getbox.php代码:

<?php
print_r($_POST[checkbox]);
?>

除非注明,均为湛蓝天空原创,转载请注明本文网址:http://skyhome.cn/js/199.html

标签:checkbox(1)
评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)