点击全选或反选只有第一个会变,其他都没有反映
<?php
include("../../admin/public/header.php");
include("../../admin/public/admin_left.php");
$sql="select * from ts_users ";
$res=mysql_query($sql);
$arr=array();
if(mysql_num_rows($res)>0){
while(($list=mysql_fetch_assoc($res))!=false){
$arr[]=$list;
}
}
?>
<div id="div">
<table border=0 cellspacing=0 width="900px">
<tr height="60px">
<th>选择</th>
<th>用户名</th>
<th>邮箱</th>
<th>手机</th>
<th>创建事件</th>
<th>最后登陆时间</th>
<th>操作</th>
</tr>
<?php if(isset($arr)) {
foreach ($arr as $vo) {
?>
<tr align="center" height="30px">
<td id="td"><input type="checkbox" value="<?=$vo['uid']?>" ></td>
<td><?= $vo['uname'] ?></td>
<td><?= $vo['email'] ?></td>
<td><?= $vo['phone'] ?></td>
<td><?= $vo['ctime'] ?></td>
<td><?= $vo['mtime'] ?></td>
<td>
<a href="./delete_uid.php?uid=<?= $vo['uid'] ?>">删除</a>
<a href="./update_uid.php?uid=<?= $vo['uid'] ?>">编辑</a>
</td>
</tr>
<?php
}
}
?>
</table>
<input type="button" value="全选" onclick="allcheck()">
<input type="button" value="反选" onclick="check()">
</div>
<script>
var div=document.getElementById("td");
var childs=div.childNodes;
function allcheck(){
for(var i=0;i<childs.length;i++){
if(childs[i].nodeName=="INPUT" && childs[i].getAttribute('type')=='checkbox'){
childs[i].checked=true;
}
}
}
function check(){
for(var i=0;i<childs.length;i++){
if(childs[i].nodeName=="INPUT" && childs[i].getAttribute('type')=='checkbox'){
if(childs[i].checked==true){
childs[i].checked=false;
}else{
childs[i].checked=true;
}
}
}
}
</script>
</body>
</html>
<td class="td"><input type="checkbox" value="<?=$vo['uid']?>" ></td>
把id='td'换成class='td'
id
整个文档只能有一个,用class