【问题标题】:Is there a submit on "Enter" option in jquery diglog plugin?jquery diglog插件中的“Enter”选项是否有提交?
【发布时间】:2009-09-09 09:03:44
【问题描述】:

网址在这里:

http://jqueryui.com/demos/dialog/#modal

假设这个对话框包含两个按钮:“OK”和“NO”,

当按下“Enter”时,我希望调用与“OK”按钮绑定的函数。

怎么做?

对话框是这样的:

<table cellpadding="0" border="0" width="100%">
    <tr align="center">
        <td align="right">name/email:</td>
        <td><input type="text" id="name" /></td>
    </tr>
    <tr align="center">
        <td align="right" valign="top">password:</td>
        <td>
                <input type="text" id="psw" />
        </td>
    </tr>
    <tr align="center">
        <td></td>
        <td><span id="loginErr"></span></td>
    </tr>
</table>

【问题讨论】:

    标签: jquery event-handling dialog


    【解决方案1】:

    将“确定”按钮分配给标签并为其提供焦点(如果第一件事不能单独正常工作)

    【讨论】:

    • 查看我的更新,无法专注于按钮。专注于某些 时它应该可以工作
    【解决方案2】:

    您可以通过添加选项对象轻松添加自定义按钮

    buttons: {
    'Button OK': function() {
      // Do something
     },
    'Button No': function() {
      // Do something
    }
    

    要在按键输入时提交表单字段,只需执行以下操作:

    $("#name").keydown(function(event){
        if(event.keyCode == "13") {
            // call the function for submit the form
        }
    });
    

    所有 KeyCode 的完整来源请在此处找到: http://unixpapa.com/js/key.html

    【讨论】:

      【解决方案3】:

      要么采用 snuffer-ch 建议的方法,要么使用 jQuery-Hotkeys 插件 http://code.google.com/p/js-hotkeys/ 让您这样做:

      $(document).bind('keydown', 'return', function(){
        //your code goes here
      });
      

      【讨论】:

        【解决方案4】:

        不,该功能不是开箱即用的,您需要自己添加它或找到一个插件来添加它(我不知道有一个在我脑海中的)。

        一种可能的解决方案是侦听对话框的keyup 事件并确定它是否源自&lt;input&gt; 元素。如果是这样,请查询buttons 成员的对话框选项并调用第一个按钮的处理函数(与单击默认按钮非常接近)。

        【讨论】:

          猜你喜欢
          • 2011-07-07
          • 2010-10-27
          • 2011-01-16
          • 1970-01-01
          • 2012-08-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多