jquery全选反选复选框+批量删除

  <li id="all_del"><span><img src="__ADMIN__/images/t03.png" /></span>删除</li>

        <table class="tablelist">
            <thead>
                <tr>
                    <th>
                        <input  type="checkbox" value=""  id="checkAll" />
                    </th>
                    <th>商品id</th>
                    <th>商品名称</th>
                    <th>缩略图</th>
                    <th>商品价格</th>
                    <th>库存</th>
                    <th>上架时间</th>
                    <th>添加时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {volist name="goods_list" id="val"}
                <tr>
                    <td>
                        <input name="checkbox_name" type="checkbox" value="{$val.goods_id}" />
                    </td>
                    <td>{$val.goods_id}</td>
                    <td>{$val.goods_name}</td>
                    <td><img src="{$val.goods_small_logo|ltrim=###,'.'}"></td>
                    <td>{$val.goods_price}</td>
                    <td>{$val.goods_number}</td>
                    <td>{$val.goods_weight}</td>
                    <td>{$val.add_time|date='Y-m-d',###}</td>
                    <td><a href="photos/goods_id/{$val.goods_id}" >查看</a>
                         <a class='del' href="{:Url('del',array('goods_id'=>$val['goods_id']))}"> 删除</a>    
                         <a href="edit/goods_id/{$val.goods_id}">编辑</a>
                    </td>
                </tr>
                {/volist}
            </tbody>
        </table>
    <script type="text/javascript">
        $('.tablelist tbody tr:odd').addClass('odd');
        //删除前提醒
        $('.del').click(function(){
            if(confirm('确定要删除吗?')){
                return true;
            }else{
                return false;
            }
        });
        //复选框
        $('#checkAll').click(function(){
           if($(this).attr('checked')){
                $("input[name='checkbox_name']").each(function(){
                    $(this).attr("checked",true);
                });
           }else{
                $("input[name='checkbox_name']").each(function(){
                    $(this).attr("checked",false);
                });
           }
        });
        //批量删除
        $('#all_del').click(function(){
           var list=$(':checkbox:checked');
           var ids="";
            list.each(function(){
                ids += $(this).val()+',';
            });
            if(ids.length==0){
                alert('请选择要删除的商品');
            }else{
                //截取最后一个
                ids=ids.substr(0,ids.length-1);
                if(confirm('确定要删除吗?')){
                    location.href="dels/goods_id/"+ids;
                }else{
                    return false;
                }  
            }
         
        });

    </script>

 

 

转载于:https://www.cnblogs.com/mengor/p/7999026.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值