js 全选、反选、批删

来源:互联网 发布:数据集成市场怎么样 编辑:程序博客网 时间:2024/05/21 22:29
$(function(){
        //全选反选
        $("#checkAll").click(function(){
            var ids=document.getElementsByName("id[]")
            // alert($(ids).attr("checked"));
            $(ids).each(function(){
                if($(this).attr("checked")!="checked"){
                    $(this).attr("checked",true)
                }else{
                    $(this).attr("checked",false)
                }    
            })    
        })
        //全不选
        $("#checkNoAll").click(function(){
            var ids=document.getElementsByName("id[]")
            // alert($(ids).attr("checked"));
            $(ids).each(function(){
               $(this).attr("checked",false)        
            })    
        })
        //批量删除
        $("#delAll").click(function(){
            //获取批量删除值
            var ids=$("input:checked");
            var idss="";
            $(ids).each(function(){
                   idss+=$(this).val()+',';
             });
             // alert(idss)
            $.get("{url:/test/del}",{"ids":idss},function(msg){
                if(msg){
                  $(ids).each(function(){
                       $(this).parents("tr").remove()
                  });
                  alert("删除成功!")
                }else{
                  alert("删除失败!")
                }
            })        
        })
        //几点技改
        $(document).on("click",".price",function(){
            var id=$(this).parent().attr("id");
            var val=$(this).html();
            // $(this).hide();
            $(this).parent().html("<input size='5' class='upda' value='"+val+"'>")
            $(".upda").blur(function(){
            var va=$(this).val();
            var _this=$(this);
                 $.get("{url:test/upda}",{"id":id,"price":va},function(msg){
                     if(msg){
                         _this.parent().html("<span class='price'>"+va+"</span>")
                         // console.log(t.html())
                         _this.remove();
                         alert("修改成功!")
                     }else{
                         alert("修改失败!")
                     }
                  })
            })
        })
        
        
        
    })
0 0
原创粉丝点击