我有一个 PHP 页面,它使用<form action="" method="post">
. 我正在进行一些 jQuery 字段验证,如果验证未通过,我想阻止表单提交。但是,即使验证未通过,它也会继续提交。
我错过了什么?.submit()
为了防止提交,我是否需要实际使用带有 jQuery 函数的按钮(而不是提交) ?(这是一个小提琴)
<form action="" method="POST">
<label for="email">Username: <br />
<input id="email" name="email" class="phPasswordTxtInputField" type="text" size="33" value=""><br />
<label for="tmp_password">Temp password:<br />
<input id="tmp_password" name="tmp_password" type="password" minlength="5" value="" default="" size="33" caption=""><br />
<label for="new_password">New password:<br />
<input id="new_password" name="new_password" type="password" minlength="5" value="" default="" size="33" caption=""><br />
<label for="verify_password">Confirm password:<br />
<input id="verify_password" name="verify_password" type="password" minlength="5" value="" default="" size="33" caption=""><br />
<div style="margin: 0px 0px 0px 160px;" id="lblConfirmPasswordMessage"></div>
<input type="submit" id="submit_password" value="Reset Password" />
</form>
<script>
function checkPasswordVerify(p,c,objId) {
if(p != c) {
var el = $(objId);
$(objId).html('<span class="passwordStrength">Please make sure the password and confirmation match.</span>');
return false;
}
return true;
}
$('#submit_password').click(function() {
checkPasswordVerify($(this).val(), $('#new_password').val(), '#lblConfirmPasswordMessage');
});
</script>