jquery全选-全不选,删除,批删,即点即改

来源:互联网 发布:ucloud 阿里云 哪个好 编辑:程序博客网 时间:2024/06/08 16:52

全选和全不选

$(document).on('click','#quan',function(){    var name_va = $(this).prop('name');//获取标签的name值        if(name_va == '全选'){         $("input[type='checkbox']").each(function(i,v)         $(v).prop("checked",true);        })         $("#quan").prop('name','全不选');         $("#quan").val('全不选');        }else{                $("input[type='checkbox']").each(function(i,v){    $(v).prop("checked",false);})    $("#quan").prop('name','全选');    $("#quan").val('全选');  }})

删除

$('#dbname').click(function(){    var dbname = $(this).data("dbname");    if(confirm("确认删除吗?")){        var _this = $(this);        $.ajax({            type: "post",            url: "?r=dbs/del_db",            data: {'dbname':dbname},            dataType: "json",            success:function(msg){                if(msg === '1'){                _this.parent().parent().parent().remove();                    }                }            });        }    });

批删

$(document).on('click','.delss',function(){    var strs = '';//定义一个空的变量            $("input[type='checkbox']").each(function(i,v){    if($(v).prop('checked') == true){        strs+=','+$(v).val();    }})    strs = strs.substr(1);    $.ajax({        type:"get",        url:"{:U('Index/dels')}",        data:{'id':strs},        dataType:"json",        success:function(msg){            $("#page_s").html(str);        }     })})

即点即改

$(".field").click(function(){    var vo = $(this).text(); //获取原来的值    $(this).hide();    $(this).next().attr('type', 'text').val(vo).focus().show();}); $(".text_field").blur(function(){    var _this = $(this); //表示当前元素    var at_tablename = $(".at_tablename").val(); //当前值    var new_val = $(this).val(); //新的值    var old_val = $(this).prev().text(); //旧的值        //判断 --- 与未修改的值相等        if(new_val === old_val){            $(this).prop('type', 'hidden');            $(this).prev().show();            return false;        }        //新的值不能为空        if(new_val === ''){            alert('修改后不能为空');            $(this).prop('type', 'hidden');            $(this).prev().show();            return false;        }        $.ajax({            type: "get",            url: "?r=fields/update_field",            data: {'new_val':new_val,},            dataType: "json",            success:function(result){                if(result === '0'){                    alert('修改失败!');                    $(this).prop('type', 'hidden');                    $(this).prev().show();                    return false;                }                if(result === '1'){                    _this.prop('type', 'hidden');                    _this.prev().show().text(new_val);                }            }        })