我不確定我的代碼出了什麼問題。我在jquery mobile中使用了兩種形式,在驗證了第一種情況後,單擊了錨標籤時,如果驗證成功,我想在#page2中轉到表單2,或者如果驗證失敗,我想繼續當前頁面。問題是如果第一個表單上的所有數據都是正確的,我可以導航到第二個表單,但如果它不正確,event.preventDefault()會被觸發,如果我填寫正確的表單,它不會讓我去2.形式第一次窗體驗證後移至第二個窗體javascript
<form action="#" method="post" data-ajax="false">
<span class="error_form" id="username_error"></span>
<label for="username">Username : <span></span></label>
<input type="text" name="username" id="username" placeholder="Enter username" value="">
<span class="error_form" id="password_error"></span>
<label for="password">Create password : <span></span></label>
<input type="password" name="password" id="password" placeholder="Enter password">
<span class="error_form" id="password_error_confirmation"></span>
<label for="passwordAgain">Confirm password : <span></span></label>
<input type="password" name="password_confirmation" id="password_confirmation" placeholder="Enter password again">
<div class="ui-grid-a">
<div class="ui-block-a">
<a href="#" data-role="button" data-icon="arrow-l" data-iconpos="left" data-transition="pop">Back</a>
</div>
<div class="ui-block-b">
<a href="#page3" id="register1" data-role="button" data-icon="arrow-r" data- iconpos="right" data-transition="pop">Next</a>
</div>
</div>
</form>
script.js, I have tried it with event.PreventDefault()
and it doent work
$('a#register1').click(function(event){
check_username();
check_password();
check_password_confirmation();
if(error_username == false && error_password == false && error_password_confirmation == false){
sessionStorage.setItem("username", $("#username").val());
sessionStorage.setItem("password", $("#password").val());
sessionStorage.setItem("password_confirmation", $("#password_confirmation").val());
$(this).attr("href", "#page3");
}else{
$(this).removeAttr("href");
}
});