简体   繁体   English

如何使用快捷键/热键jQuery控制组合框(html)?

[英]How to control combo box (html) with shortcut key / hotkey jQuery?

I have combo box like this : 我有这样的组合框:

<select id="shift" name="s">
  <option value="1" selected="selected">Shift 1</option>
  <option value="2">Shift 2</option>
  <option value="3">Shift 3</option>
</select>

Now, I want to access or control this combo box with shortcut key / hotkey. 现在,我想使用快捷键/热键访问或控制此组合框。 For example when I press the "alt+s" button, so I can see the list of combo box and I can choose with press "up / down" button. 例如,当我按下“ alt + s”按钮时,可以看到组合框列表,并且可以通过按下“上/下”按钮进行选择。

I need this shortcut key / hotkey to change the click on mouse. 我需要此快捷键/热键来更改鼠标单击。 I need this to create mouseless application (application can run without a mouse). 我需要这个来创建无鼠标应用程序(该应用程序无需鼠标即可运行)。 Is there a solution for this case? 有这种情况的解决方案吗?

Seems like you will use hotkeys throughout in this project of yours. 似乎您将在整个项目中始终使用热键。 May I suggest jQuery Hotkeys from the creator of jQuery. 我可以建议jQuery创建者提供的jQuery快捷键。 It allows mapping all combinations of keys to various events. 它允许将键的所有组合映射到各种事件。

In your case, you might want to create an hotkey event, when pressed said combination, would trigger a 'focus' (to focus on combobox) or 'click' (to open up the list) event on your combobox. 在您的情况下,您可能想创建一个热键事件,当按下所述组合时,将在您的组合框上触发一个“焦点”(聚焦于组合框)或“单击”(打开列表)事件。

 $(document).keypress(function (event) {
    var keyPressed = event.keyCode;
    var altPressed = event.altKey;
    if (altPressed && keyPressed == /* key code for 's'*/) {
        $("#altPressed").click();            
    }
});

Once its focused, up and down keys will workd for navigation. 一旦它的重点, updown键将workd进行导航。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM