form.val无法赋值

提问 未结
2 201
Martin1573
Martin1573 2018-5-11
悬赏:20飞吻
版本:layui 2.3.0-rc1 浏览器:
在html中form.val赋值没问题
在jsp中赋值就报Uncaught TypeError: form.val is not a function错误
form的监听时间都可以用,代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>编辑用户</title>
<link rel="stylesheet" href="../../resources/layui/css/layui.css">
</head>
<body style="margin: 5px;">
<form class="layui-form" action="" lay-filter="example" style="margin: 5px;">
<div class="layui-form-item">
<label class="layui-form-label">账号</label>
<div class="layui-input-block">
<input type="text" name="account" lay-verify="title" autocomplete="off" placeholder="请输入账号" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">用户名</label>
<div class="layui-input-block">
<input type="text" name="uname" lay-verify="title" autocomplete="off" placeholder="请输入用户名" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">密码</label>
<div class="layui-input-block">
<input type="password" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="save">保存</button>
<button class="layui-btn layui-btn-primary" lay-submit lay-filter="cancel">取消</button>
</div>
</div>
</form>
<script src="../../resources/layui/layui.js"></script>
<script>
layui.use(['form', 'layedit', 'laydate'], function(){
var $ = layui.$,form = layui.form,layer = layui.layer
,layedit = layui.layedit,laydate = layui.laydate;
//layer.msg(jsonstr);

//监听提交
form.on('submit(save)', function(data){
layer.alert(JSON.stringify(data.field), {
title: '最终的提交信息'
})
//var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
//parent.layer.close(index); //再执行关闭
return false;
});
form.on('submit(cancel)',function(){
var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
parent.layer.close(index); //再执行关闭
});
form.val('example',{"uname":"test","account":"12395"});
});
</script>
</body>
</html>
回帖
  • 咱能不能不要直接把代码扔进来,不是有个代码按钮嘛[晕]
    0 回复
  • 贤心
    贤心 (管理员)
    2018-5-11
    覆盖版本后,记得更新下缓存。。
    0 回复