码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2015-10-30 07:06:53      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:

<!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;

    }
?>

 

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

标签:

原文地址:http://www.cnblogs.com/leigood/p/4922280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!