layui表单页面编辑字段
首先呢,咱们在页面的显示表单中添加2个属性,如图:
可以看到标红的字段哈,然后现在页面上的字段是可以的编辑的了,如下图:
但是,现在还是不能修改的,必须要写上监听事件:
table.on('edit(test)', function(obj) {
var reg = new RegExp("^[0-9]*$");
//var hex = new RegExp("^#?([a-f0-9]{6}|[a-f0-9]{3})$/");
var value = obj.value ,// 得到修改后的值
data = obj.data ,// 得到所在行所有键值
field = obj.field; // 得到字段
var old=$(this).prev().text();//旧值
if(field == "unit" && !hex(obj.value)){
obj.update({unit:old});
layer.msg('修改失败、请输入16进制的值', {
"icon" : 2,
"time" : 2000
});
}else{
var now_date = new Date();
var jsonEntity = {};
jsonEntity["id"] = data.id;
jsonEntity[field] = value;
jsonEntity["projectId"] = data.projectId;
zsg(_path + 'devDetail/updDevDetail.do', jsonEntity, obj);
}
zsg的话就是一个增删改查的方法,额,放出来吧:
// 增删改操作
function zsg(url, jsonEntity, obj) {
$.ajax({
type : "post",
url : url,
data : jsonEntity,
success : function(mydata) {
if (mydata.data == "delSuccess") {
layer.msg("删除单个成功", {
"icon" : 6,
"time" : 2000
});
obj.del();
} else if (mydata.message == "updSuccess") {
layer.msg("信息修改成功", {
"icon" : 6,
"time" : 2000
});
flush(currentPage);
} else if (mydata.message == "saveSuccess") {
layer.msg("数据添加成功", {
"icon" : 6,
"time" : 2000
});
flush(1);
} else if (mydata.status == "saveFail"){
layer.msg("数据添加失败:"+mydata.message, {
"icon" : 2,
"time" : 2000
});
flush(1);
} else if (mydata.status == "fail"){
layer.msg("数据添加失败:"+mydata.message, {
"time" : 5000,
"icon" : 2
});
flush(1);
} else if (mydata.data == "NumOfTicketsIs0") {
layer.msg("门票已售空", {
"icon" : 5,
"time" : 2000
});
} else {
layer.msg("操作失败!未知错误。", {
"icon" : 2,
"time" : 2000
});
flush(currentPage);
}
},
error : function() {
layer.msg("对不起,服务器异常", {
"icon" : 3,
"time" : 2000
});
}
});
}
ok,给显示表单加完属性,写上监听,就ok了