我需要一些有关远程规则的 jquery 验证插件的帮助。即使输入无效,表单似乎也会提交。当我第一次提交表单时,验证工作正常,但如果我再次单击该按钮,表单将提交无效输入。
有任何想法吗?谢谢
<html lang="en">
<head><meta charset="utf-8"><title>test</title></head>
<body>
<form id="validate" method="post" action="?go=submit">
<input type="text" placeholder="test 1" id="test1" name="test1" value="test@test.com" class="required email">
<br/>
<input type="text" placeholder="test 2" id="test2" name="test2" value="" class="required" minlength="5">
<button type="submit">Save</button>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.min.js"></script>
<script>
$(function() {
$("#validate").validate();
$("#validate").removeAttr("novalidate");
if($('#test1').length) {$("#test1").rules("add", {remote: "/test1", messages: {remote: "test 1 failed."}});}
if($('#test2').length) {$("#test2").rules("add", {remote: "/test2", messages: {remote: "test 2 failed."}});}
});
</script>