我有以下形式.submit()不開火形式
<form action="" method="post" name="loginForm" id="loginForm">
<div id="spinnerInsert">
<div class="form-content"><input type="text" name="loginUser" id="loginUser" class="validate[required,minSize[3]]" required /><span class="form_highlight"></span><span class="form_bar"></span><label for="loginUser">Username</label><span class="form_hint">Enter your username here</span></div>
<div class="form-content"><input type="password" name="loginPassword" id="loginPassword" class="validate[required]" required /><span class="form_highlight"></span><span class="form_bar"></span><label for="loginPassword">Password</label><span class="form_hint">Enter your password here</span></div>
</div>
<div class="form-content buttons"><p><input name="action-login" type="submit" id="action-login" value="Sign In" class="button confirm" style="width: 140px;" /><br/><a href="">Register</a> · <a href="">Forgot Password</a></p></div>
</form>
,然後在腳本
$('form#loginForm').submit(function(event) {
// Get data and submit
$('#spinnerInsert').spin();
$.getJSON("lib/class/class.login.php", {loginUser: $('input#loginUser').val(), loginPassword: $('input#loginPassword').val(), queryType: "1"})
.done(function(response) {
$('#spinnerInsert').spin(false);
if(response.success===0){
// Show Error
toastr.error(response.message, 'Error');
// If totalFails > 4, lock account and offer to reset password or email admin
if(response.totalFails>4) {
$('article#pageForm').html('<p id="accountLocked">Sorry, your account has been locked. Please <a href="">reset your password</a> or <a href="mailto:adminemail">contact the site admin</a> to unlock your account</p><p><a href="javascript:backToLogin();">Back to Sign In</a></p>');
}
} else {
// Load Authentication Section
$('article#pageForm').html(response.data);
}
});
event.preventDefault();
return false;
});
但由於某些原因,我每次按一次下面的代碼提交它只是重新加載這一頁。它根本不會觸發我的腳本。
它昨天工作,但不是今天,我不記得改變任何事情。我也試過$(document).on('submit','form#loginForm',function(event) {
。
打開瀏覽器的錯誤控制檯,勾選「保存登錄」複選框,並期待在錯誤消息('$(...)。自旋不是一個function') – JJJ