javascript的全选,反选,全不选,即点即改,批量删除

前台页面

<div class="headbar">
    <div class="position"><span>商品</span><span>></span><span>商品管理</span><span>></span><span>商品列表</span></div>
    <div class="operating">
        <a href="javascript:void(0)">
            <button id="check_all">全选</button>
        </a>
        <a href="javascript:void(0)">
            <button id="Invert">反选</button>
        </a>
        <a href="javascript:void(0)">
            <button id="check_No">全不选</button>
        </a>
        <a href="javascript:void(0)">
            <button id="del_all">批量删除</button>
        </a>
    </div>

    

    <div class="field">
        <table class="list_table">
            <colgroup>
                <col width="40px" />
                
                <col />
                <col />
                <col />
                
            </colgroup>

            <thead>
                <tr>
                    <th>选择</th>
                    <th>商品ID</th>
                    <th>商品名称</th>
                    <th>销售价</th>
                    <th>库存</th>
                    <th>操作</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

<form action="" method="post" name="orderForm">
    <div class="content">
        <table class="list_table">
            <colgroup>
                <col width="40px" />
                <col />
                <col />
                <col />
                
            </colgroup>

            <tbody>
                {query: name=test}
                {if:$item['is_del'] == 0}
                <tr vid="{$item['id']}">
                    <td><input type='checkbox' name='id[]' value='{$item['id']}' /></td>
                    <td>{$item['id']}</td>
                    <td>{$item['name']}</td>
                    <td><a href="javascript:void(0)" class='price'>{$item['price']}</a></td>
                    <td>{$item['stock']}</td>
                    <td>
                        <a href='{url:/tools/ad_position_edit/id/$item[id]}'><img class="operator" src="{skin:images/admin/icon_check.gif}" alt="获取广告位代码" title="获取广告位代码" /></a>
                        <a href='javascript:void(0)' οnclick="delModel({link:'{url:/tools/ad_position_del/id/$item[id]}'});"><img class="operator" src="{skin:images/admin/icon_del.gif}" alt="删除" +title="删除" /></a>
                    </td>
                </tr>
                {/if}
                {/query}

            </tbody>
        </table>
    </div>
</form>
<script>
//全选
    $('#check_all').click(function(){
        $("input[name = 'id[]']").each(function(){
            this.checked = true;
        });
    });
//全不选
$('#Invert').click(function(){
        $("input[name = 'id[]']").each(function(){
            this.checked = false;
        });
    });
//反选
$('#check_No').click(function(){
        $("input[name = 'id[]']").each(function(){
            if(this.checked == true){
                this.checked = false;
            }else{
                this.checked = true;
            }
        });
    });
//批量删除
$('#del_all').click(function(){
    //存放选中ID的值
            var arrUserid = " ";
            $("input[name = 'id[]']").each(function() {
                if (this.checked == true)
                {
                     arrUserid += $(this).val() + ",";
                }
            });
            $.get("{url:/test/del_all}",{id:arrUserid},function(data){
                // alert(data);
        if(data == 1)
        {
            $("input[name='id[]']").each(function()
            {
                if(this.checked == true)
                {
                $(this).parents('tr').remove();
                }        
            });
            alert('删除成功');
        }
        else
        {
        alert('删除失败');
        }

            });
});
//即点即改
$(document).on('click','.price',function(){  
    var price = $(this).html();
    $(this).parent().html('<input type="text" name="money" value=" '+price+' "/>');
})
$(document).on('blur','input[name = "money"]',function(){  
    var price = $(this).val();
    var vid = $(this).parent().parent().attr('vid');
    var obj = $(this);
    $.get("{url:/test/update}",{'id':vid,'price':price},function(data){
        
        if(data == 1){
            obj.parent().html('<a href="javascript:void(0)" class="price">'+price+'</a>');
            alert('修改成功');
        }else{
            obj.parent().html('<a href="javascript:void(0)" class="price">'+price+'</a>');
            alert('修改失败');
        }
        
    })
    

})
</script>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值