php中常用的全选函数

<script>function checkall(form, prefix, checkall) {
for(var i = 0; i < form.elements.length; i++) {
var e = form.elements[i];
if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
e.checked = form.elements[checkall].checked;
}
}
}</script>
<form>
<input type=”checkbox” name=”chkall” onclick=“checkall(this.form, ‘del’, ‘chkall’)”>全选
<input type=”checkbox” name=”del[]” value=1>删除1
<input type=”checkbox” name=”del[]” value=2>删除2
<input type=”checkbox” name=”del[]” value=3>删除3
<input type=”checkbox” name=”del[]” value=4>删除4
<input type=”submit” name=”modsubmit” value=”提交”>
</form>
checkall函数中的”del”为表单中del[]这类的前缀,"chkall”为单击的表单

Leave a Reply