jQuery批量操作

2017-11-22  本文已影响0人  woann

html

<th><input type="checkbox" id="all" ></th>
//遍历中的checkbox
<td><input type="checkbox" name="ids" value="{{$v->id}}" ></td>

代码如下

//全反选
$(document).on('click','#all',function(){
        console.log(1);
        if(this.checked){
            $('input[name="ids"]').prop("checked", true);
        }else{
            $('input[name="ids"]').prop("checked", false);
        }
    });
$(document).on('click','input[name="ids"]',function(){
        if($('input[name="ids"]:checked').length == $('input[name="ids"]').length){
            $('#all').prop("checked", true);
        }else{
            $('#all').prop("checked", false);
        }
    })
//执行批量删除函数
function delMore(url){
    if($('input[name="ids"]:checked').length == 0){
        swal('糟糕','请先选中要删除的条目','error');
        return false;
    }
    myConfirm('确定批量删除?','删除操作是不可逆的,是否继续?',function(){
        var ids = '';
        $('input[name="ids"]:checked').each(function(){
            ids+=$(this).val()+',';
        })
        ids = ids.substr(0, ids.length - 1);
        window.location.href=url+"/"+ids;
    });
}
上一篇 下一篇

猜你喜欢

热点阅读