行内编辑 实现 ajax提交

//只能点击一次
var can_click = true;
function Layui_edit(){
//数据可编辑
$(".My_edit").each(function(){
$(this).click(function () {
if(can_click) {
can_click = false;
var goodsid =this.dataset.id;
console.log(goodsid)
//变为输入框
var text = $(this).html();
$(this).html('<input type="text" class="layui-input layui-table-edit" value="' + text + '">');
$(this).children("input").val("").focus().val(text);

                //移除光标 恢复原样
                $(this).find(".layui-table-edit").blur(function () {
                    // console.log($(this));
                    var data = $(this).val();
                    $(this).parent().html(data);
                    $(this).remove();
                    can_click = true;

                    ajax_("admin/Bankgoods/updatebankpoints", {id: goodsid,bankpoints:data}, function (r) {
                        success_res(r);
                    })
                })
            }
        })
    })

}
Layui_edit();

猜你喜欢

转载自blog.51cto.com/xihan/2469800