简体   繁体   中英

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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