65 lines
1.7 KiB
HTML
65 lines
1.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
|
|
<head>
|
|
<th:block th:include="include :: header('验证测试')" />
|
|
</head>
|
|
<body>
|
|
<div class="col-sm-8">
|
|
<div>
|
|
<form role="form" class="form-inline" id="form-user-add">
|
|
<div class="form-group">用户名:
|
|
<label for="name" class="sr-only">用户名</label>
|
|
<input id="name" name="name" placeholder="请输入用户名" class="form-control">
|
|
</div>
|
|
<button class="btn btn-white" type="submit" onclick="submitHandler()">登录</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<th:block th:include="include :: footer" />
|
|
<script>
|
|
var ctx = [[@{/}]];
|
|
$("#form-user-add").validate({
|
|
onkeyup: false,
|
|
rules:{
|
|
name:{
|
|
minlength: 1,
|
|
maxlength: 20,
|
|
remote: {
|
|
url: ctx+"/test/testVerifyName",
|
|
type: "post",
|
|
dataType: "json",
|
|
data: {
|
|
"name": function() {
|
|
return $.common.trim($("#name").val());
|
|
}
|
|
},
|
|
dataFilter: function(data, type) {
|
|
return $.validate.unique(data);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
messages: {
|
|
"name": {
|
|
remote: "用户已经存在"
|
|
}
|
|
},
|
|
focusCleanup: true
|
|
});
|
|
|
|
function submitHandler() {
|
|
var user=$.common.trim($("#name").val());
|
|
if ($.validate.form()) {
|
|
alert("用户【"+user+"】不存在!");
|
|
|
|
}
|
|
else{
|
|
alert( "用户【"+user+"】已存在!");
|
|
}
|
|
}
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
</html> |