//formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
layui.use(['form'], function() {
//引入layui from模块
var form = layui.form;
//为from赋值,赋值方式:"name": "value".
form.val('formTest ', {
"username": "贤心",
"password": "123456",
"interest": 1,
//复选框选中状态
"like[write]": true,
//开关状态
"close": true,
"sex": "女",
"desc": "我爱 layui"
});
})
//注意直接给对象是不能赋值的如下
var data ={
"username": "贤心",
"password": "123456",
"interest": 1,
//复选框选中状态
"like[write]": true,
//开关状态
"close": true,
"sex": "女",
"desc": "我爱 layui"
};
//这样并不能赋值成功
form.val('example', data);
网友评论