jQuery实现全选和反选和临时页面删除

本人用的是3层调的数据库动态生成的table表格;代码如下:
public void load()
        {
            
            StringBuilder sb = new StringBuilder();
            sb.Append("<table>");
            sb.Append("<tr><td>选择</td><td>编号</td><td>标题</td><td>内容</td><td>图片</td></tr>");
            SqlDataReader read = WebApplication1.DataCass.DbHelperSQL.ExecuteReader("select id,title,content,imagepath FROM temporary");
            while (read.Read())
            {
                string id =Convert.ToString(read.GetSqlInt32(read.GetOrdinal("id")));
                string title = read.GetString(read.GetOrdinal("title"));
                string content = read.GetString(read.GetOrdinal("content"));
                string img = read.GetString(read.GetOrdinal("imagepath"));
                sb.Append("<tr class=tr><td><input type=checkbox name=check /></td><td>" + id + "</td><td>" + title + "</td><td>" + content + "</td><td><img class=gg src=" + img + "/></td></tr>");
            }
          
            sb.Append("</table>");
            insert.InnerHtml = sb.ToString();
        }
接下来就是jquery的代码了:
 <script type="text/javascript">
        $(function () {
            //全选
            $('#checkall').click(function () {
                $('[name=check]').attr('checked', $(this).is(':checked'))
                //                if ($('[name=check]').checked=false) {
                //                    $('#checkall').attr('checked',false)
                //                }
            })
            //反选
            $('#checkother').click(function () {
                $('[name=check]').each(function () {
                    if ($(this).is(':checked')) {
                        $(this).attr('checked', false);
                    }
                    else { $(this).attr('checked', true); }
                })
            })
            //删除代码
            $('#btn').click(function () {
                $('[name=check]:checked').each(function () {
                    if ($(this).is(':checked')) {
                        //方法一
                        //var i = $('table tr td input').index(this)
                        //$('table tr td :checkbox:checked').parent().parent().remove()

                        //方法二
                        var i = $('table tr td input').index(this)+1
                        $('table').find('tr').filter(':eq('+i+')').remove()
                    }
                })

                //$('tr:eq(' +  + ')').remove();
            })
            $('table img').mouseover(function (e) {
                $('#imgg').attr('src', $(this).attr('src'))
                $('#imgg').css('left', 735);
                $('#imgg').css('top', e.pageY - 10);
                $('#imgg').show()
            })
            $('table img').mouseout(function () {
                $(this).attr('style', 'background-color:rgb(239,254,253)');
                $('#imgg').hide()
            })
        })
    </script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值