【发布时间】:2013-09-02 20:05:36
【问题描述】:
我有这个 html 表单,它的提交按钮有一些奇怪的行为。
当我单击“提交”按钮时,它一直处于按下状态,但没有提交表单。但是,如果表单是通过其他方式提交的,比如在键盘上按 Enter,或者在 Mobile Safari (iDevice) 上按 GO,一切正常。我正在使用 jQuery 移动顺便说一句。
谁能明白为什么会这样?
HTML
<div class='login' id='login'>
<div class='login-header'>Please Login</div>
<div class='alert-error' id='login-error' style='display:none;'>
Please check your username and password and try again.
</div>
<form id='login_form'>
<br>
<p class='label'>Username</p>
<input type='text' name='username'>
<p class ='label'>Password</p>
<input type='password' name='password'>
<button type='submit' data-theme='a' id='login-button'>Login</button>
</form>
</div>
JS
$('#login_form').submit(function(e) {
e.preventDefault();
e.stopPropagation();
var serializedFormData = $(this).serialize();
// blah blah ajax form submit
});
});
编辑
看来我可以通过切换以下行来解决我的问题:
<button type='submit' data-theme='a' id='login-button'>Login</button>
与
<input type='submit' value='Submit'>.
任何知道这为什么奏效的人仍有待获得声誉。
【问题讨论】:
-
不,按钮标签完全没问题。
标签: javascript jquery html forms jquery-mobile