這我的代碼plz幫助我的任何一個submitHandler:功能不工作
$(document).ready(function() {
// validate signup form on keyup and submit
var validator = $("#signupform").validate({
rules: {
username: {
required: true,
minlength: 6,
maxlength: 12,
remote:"users.php"
},
password: {
required: true,
minlength: 6,
maxlength: 12
},
email:
{
required: true,
minlength: 15,
maxlength: 50,
remote:"email.php"
}
},
messages: {
username: {
minlength: "username is 6 to 12 characters",
maxlength: "username is 6 to 12 characters",
required: " username should be required",
remote: " username should be already exists"
},
password: {
minlength: "password is 6 to 15 characters",
maxlength: "password is 6 to 12 characters 12",
required: " password should be required",
},
email: {
minlength: "Email is 15 to 50 characters",
maxlength: "Email is 15 to 50 characters",
required: " Email should be required",
remote: " Email should be already exists"
}
},
// specifying a submitHandler prevents the default submit, good for the demo
submitHandler: function()
{
alert("submitted!---------");
$("#signupform").submit();
},
// the errorPlacement has to take the table layout into account
errorPlacement: function(error, element)
{
error.prependTo(element.parent().next());
},
// set this class to error-labels to indicate valid fields
success: function(label) {
// set as text for IE
label.html(" ").addClass("checked");
}
});
// propose username by combining first- and lastname
$("#username").focus(function() {
var firstname = $("#firstname").val();
var lastname = $("#lastname").val();
if(firstname && lastname && !this.value) {
this.value = firstname + "." + lastname;
}
});
});
和窗體是
<form id="signupform" name="signupform" method="post" action="register.php" style="padding-top:70px;" >
<table align="center" style="height:200px;">
<tr>
<td class="field"><span style="width:150px;color:black;font-weight:bold;">Username:</span> <input id="username" name="username" style="height:25px;width:155px;" onKeyPress='return alphanumericPass(event, false)' type="text" value="Username (6 to 12 chars)" maxlength="12" onfocus="if(this.value=='Username (6 to 12 chars)')this.value=''" onblur="if(this.value=='')this.value='Username (6 to 12 chars)'" placeholder="Username" /></td>
<td class=""></td>
</tr>
<tr>
<td class="field"><span style="width:150px;color:black;font-weight:bold;">Password:</span> <input id="password" name="password" style="height:25px;width:155px;" onKeyPress='return alphanumericPass(event, false)' type="password" maxlength="12" placeholder="Password" /></td>
<td class=""></td>
</tr>
<tr>
<td class="field" align="left"><span style="width:150px;color:black;font-weight:bold;">Email:</span> <input id="email" name="email" style="height:25px;width:155px;" type="text" value="Email Address" onfocus="if(this.value=='Email Address')this.value=''" onblur="if(this.value=='')this.value='Email Address'"/></td>
<td class=""></td>
</tr>
<tr>
<td style="width:200px;"><div><font size="1" color="#000000">By clicking 'Register Now' you are agreeing to our <a href="terms_con.php" target="_blank" style="color:red" > Terms and Conditions </a></font></div> </td>
</tr>
<tr align="">
<td class="field" align="" colspan="2" style="padding-left:70px;">
<input align="left" value="" id="signupsubmit" name="signup" type="image" src="images/nsignup.png" />
</td>
</tr>
</table>
</form>
當您嘗試通過註冊按鈕提交表單時,您能否提供一些關於究竟發生的附加信息?是否有任何驗證發生,你在JavaScript控制檯中遇到錯誤? – burnedikt
什麼,具體是錯的?你的錯誤日誌中有什麼?發佈了大量的代碼,並要求人們都認識到這個問題,並解決它不可能得到很多幫助。 – sgroves
我正在提交表單,但頁面不重定向到register.php.when我們點擊註冊按鈕submithandler警報不顯示。 – vamsip