夺命雷公狗jquery---49单选,反选,全不选实战数据库信息

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style type="text/css">
        table{
            width:800px;
            height:1px solid red;
            border-collapse:collapse;
        }

        table tr th,table tr td{
            border:1px solid red;
            size:12px;
        }
        </style>
        <script src="js/jq8.js"></script>
        <script>
            //jQ测试环境是在1.8.3,2.X版本出现了问题
            jQuery.fn.extend({

                qx:function(){
                    this.attr('checked',true);
                },

                bx:function(){
                    this.attr('checked',false);
                },

                fx:function(){
                    for(var i=0;i<this.length;i++){
                        if(this[i].checked == true){
                            this[i].checked = false;
                        }else{
                            this[i].checked = true;
                        }
                    }
                }
            });

            $(function(){
                $('#btnqx').bind('click',function(){
                    $(':checkbox').qx();
                });

                $('#btnbx').bind('click',function(){
                    $(':checkbox').bx();
                });

                $('#btnfx').bind('click',function(){
                    $(':checkbox').fx();
                });
            });
        </script>
    </head>
    <body>
        <form action="" method="POST">
            <table>
                <tr>
                    <th>编号</th>
                    <th>帐号</th>
                    <th>注册时间</th>
                    <th>操作</th>
                </tr>
                <?php
                    mysql_connect('localhost','root','') or die('数据库连接失败');
                    mysql_select_db('xsphp');
                    mysql_set_charset('utf8');

                    //组装sql语句
                    $sql = 'select * from admin limit 10';
                    $res = mysql_query($sql);
                    while($row = mysql_fetch_assoc($res)){
                ?>
                <tr>
                    <td><?php echo $row['id']; ?></td>
                    <td><?php echo $row['username']; ?></td>
                    <td><?php echo date('Y-m-d h:i:s',$row['addtime']); ?></td>
                    <td><input type="checkbox" name="id[]" value="<?php echo $row['id']; ?>" /></td>
                </tr>
                <?php
                    }
                ?>
                <tr>
                    <td align="right" colspan="4">
                        <input type="button" id="btnqx" value="全选">
                        <input type="button" id="btnbx" value="全不选">
                        <input type="button" id="btnfx" value="反选">
                        <input type="submit" name="sub" id="btnok" value="批量删除">
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>
<?php
    if($_POST['sub']){
        $id = $_POST['id'];
        $ids = implode(',',$id);

        //批量删除
        $sql = "delete from admin where id in($ids)";
        echo $sql;

    }
?>

 

posted @ 2015-10-30 03:39  夺命雷公狗  阅读(196)  评论(0编辑  收藏  举报