【问题标题】:Jquery dialog submit form by Enter KeyJquery 对话框通过 Enter 键提交表单
【发布时间】:2014-08-22 14:26:18
【问题描述】:

我想通过按回车键为 Jquery 对话框提交表单。

HTML

<!-- Pin Notification Form -->
<div id="pin-dialog-form" title="Verification Pin">
   <div id="agent_pin_container">
      <input type="password" name="verification_pin" id="verification_pin"
      value="" class="form-control" placeholder="Verification Pin" />
</div>
</div>

JQUERY

$( "#pin-dialog-form" ).dialog({
autoOpen: false,
height: 200,
width: 300,
modal: true,
buttons: {
    "Submit": function() {
        // PROCESS
    },
    Cancel: function() {
        $( this ).dialog( "close" );
    }
},
close: function() {
    $( this ).dialog( "close" );
}
});

现在,我不能在这里使用这种类型的代码,if (e.keyCode == 13) {。因为,表单是由模态窗口本身提交的。另一方面,我不能使用它,

open: function() {
  $(this).parents('.ui-dialog-buttonpane button:eq(0)').focus(); 
}

因为,我需要先输入 PIN,然后再关注提交按钮。 还有其他方法吗? 谢谢。

【问题讨论】:

标签: javascript jquery html forms


【解决方案1】:

根据 cmets,您应该能够使用以下方法在整个文档范围内获取按键:

$(document).keypress(function(e){
  if (e.keyCode == 13) {
    // CODE TO SUBMIT THE FORM either AJAX or *form*.submit()
    // CODE TO CLOSE THE MODAL
  }
});

来源:

Submitting a form on 'Enter' with jQuery?

Capture key press without placing an input element on the page?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 2012-10-24
    • 1970-01-01
    相关资源
    最近更新 更多