【发布时间】:2016-11-11 11:42:21
【问题描述】:
我使用 Thymeleaf 作为视图引擎。
Jquery 脚本引发语法错误。
请注意,我没有在此处发布控制器,因为它运行良好。
这里是代码
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Add Author</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="../public/bootstrap-3.3.6-dist/css/bootstrap.css" th:href="@{/bootstrap-3.3.6-dist/css/bootstrap.css}"/>
<script src="../public/jquery/jquery-3.0.0.min.js" th:src="@{/jquery/jquery-3.0.0.min.js}"></script>
</head>
<body>
<h1>Add New Author</h1>
<div class="col-lg-3" >
<form class="addAuthorForm" role="form" action="#" th:action="@{/author/new-author}" th:object="${addNewAuthor}" method="post">
<div th:class="form-group" th:classappend="${#fields.hasErrors('phone')}? 'has-error'">
<label>Phone</label>
<input class="form-control" type="text" th:field="*{phone}" placeholder="Enter author's phone number"/>
<p th:if="${#fields.hasErrors('phone')}" class="label label-danger" th:errors="*{phone}">Phone Error</p>
</div>
<button type="submit" class="btn btn-default">Add</button>
<button type="reset" class="btn btn-default">Reset</button>
</form>
</div>
<script type="text/javascript">
$(document).ready(function() {
$(".addAuthorForm").validate(
{
rules: {
name: {
required : true,
remote : {
url: "<spring:url value='/author/isexist.html'/>",
type: "get",
data: {
phone: function() {
return $("#phone").val();
}
}
}
}
},
messages: {
name: {
remote: "Phone number already exists!"
}
}
}
);
});
</script>
</body>
</html>
这是错误,
我不明白这里有什么问题。请求您的指导。
【问题讨论】:
-
这是一个非常基本的语法错误,你可能需要做一些关于javascript调试的基础教程。
标签: javascript jquery spring-boot thymeleaf