AdR*_*ock 1 forms jquery keypress submit form-submit
我有一个表单,在输入文本框中我输入一个数字,然后按ENTER键,我使用jQuery将值附加到textarea.一切正常.
我遇到的问题是,如果我添加一个提交按钮来提交表单,只要我按下ENTER,它就会提交表单.
我想要它做的不是在按Enter键时提交表单,而是仅在单击提交按钮时提交表单.
我尝试过使用preventDefault()并返回false,这将停止按Enter键提交表单,但如果我在提交按钮上添加一个click事件来提交表单,它什么都不做.我在提交之前在点击功能中发出警报,但是火灾但表格没有提交
<form id="toteform" method="post" action="blah.php">
<input type="text" name="bin" id="bin" maxlength="4" autocomplete="off" />
<input type="text" name="totes" id="tote" maxlength="4" autocomplete="off" />
<input type="button" name="submit" class="submit" id="submit" value="Submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
jQuery的
$("#submit").click(function() {
$('#toteform').submit();
});
$('#bin').focus();
$('#bin').keypress(function(e) {
if(e.which == 13) {
$('#tote').focus();
}
});
$('#tote').keypress(function(e) {
if(e.which == 13) {
// more code here to do other things
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13621 次 |
| 最近记录: |