我正在使用jQuery驗證與jQuery Mobile的移動應用程序。我一直在努力爭取這項工作很長時間,看不出有什麼問題。基本上,表單提交時不會觸發任何驗證。jQuery驗證沒有驗證表單,但沒有拋出錯誤
我已經回溯了一點點,並從示例頁面http://jquery.bassistance.de/validate/demo/複製了jquery和validate.js的版本。仍然無法正常工作:(
<script type="text/javascript">
$.validator.setDefaults({
submitHandler: function() { alert("submitted!"); }
});
$().ready(function() {
// validate the comment form when it is submitted
//$("#commentForm").validate();
// validate signup form on keyup and submit
$("#signupForm").validate({
rules: {
username: {
required: true,
minlength: 2
},
password: {
required: true,
minlength: 5
},
password2: {
required: true,
minlength: 5,
equalTo: "#password"
},
email: {
required: true,
email: true
},
},
messages: {
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 2 characters"
},
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
password2: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long",
equalTo: "Please enter the same password as above"
},
email: "Please enter a valid email address"
}
});
</script>
窗體被初始化在PHP中:
可能引起問題 echo "<form id=\"signupForm\" action='".$_SERVER['PHP_SELF']."' method=\"post\">";
啊,這麼小的一件事!這是沒有出現在Firebug :( 這會引起錯誤消息,但我不能阻止它提交表單,如果必填字段爲空。任何想法? – user601606 2011-03-11 10:31:32
提交處理程序部分似乎並不如果我提交表單,警告框不會彈出,但表單仍然提交,因此,即使內容無效,表單也會提交:( – user601606 2011-03-11 11:18:52
排序。似乎jQuery驗證工作只有jquery.mobile-1.0a2!感謝您的幫助。 – user601606 2011-03-11 12:03:24