Home > Backend Development > PHP Tutorial > javascript - Can't all the php user background management be selected?

javascript - Can't all the php user background management be selected?

WBOY
Release: 2016-07-06 13:53:43
Original
837 people have browsed it

javascript - Can't all the php user background management be selected?


When you click to select all or invert the selection, only the first one will change, and the others will not be reflected


<code><?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></code>
Copy after login
Copy after login

Reply content:

javascript - Can't all the php user background management be selected?


When you click to select all or invert the selection, only the first one will change, and the others will not be reflected


<code><?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></code>
Copy after login
Copy after login

There can only be one

id in the entire document, use class

<code><td class="td"><input type="checkbox" value="<?=$vo['uid']?>" ></td></code>
Copy after login

Replace id='td' with class='td'

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template