【发布时间】:2013-02-28 00:58:00
【问题描述】:
我需要一些关于远程规则的 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>
【问题讨论】:
-
您能否在开发者工具中看到 AJAX 调用是否正在发生?
-
您能否帮助我们了解您如何在不重置表单的情况下多次提交此表单?您是在谈论成功提交还是只是单击按钮?
-
另外,为什么要删除
novalidate属性?这是由插件自动添加的,不应删除。