layui怎么赋值和获取form表单
layui怎么赋值和获取form表单,下面织梦云小编为您解答:
有如下layui表单:
向表单赋值:
有如下layui表单:
<form class="layui-form" action="" lay-filter='testForm'>
<div class="layui-form-item">
<label class="layui-form-label">账号</label>
<div class="layui-input-block">
<input type="text" name="username" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">密码框</label>
<div class="layui-input-inline">
<input type="password" name="pass" class="layui-input">
</div>
</div>
</form>
获取表单的所有值:
let data = layui.form.val(`testForm`);
console.log(" ~ file: widget.js ~ line 209 ~ data", data);
向表单赋值:
layui.form.val("testForm", {
"username": "lele"
,"pass": "123456"
});