How do I replace a keystroke with jQuery?

前端 未结 1 1154
春和景丽
春和景丽 2021-01-22 03:55

I need to be able to replace a keystroke with jQuery. When the right arrow is pressed, I want the tab key to be pressed instead. So far I have:



        
1条回答
  •  情话喂你
    2021-01-22 04:51

    You can't simulate actual keypresses with javascript. It's a core component of browser security. Imagine being able to simulate Alt-Tab, or Ctrl-Shift-Del.

    You can, of course, define a method that encapsulates the behavior you want to trigger, and call that method when specific keys are pressed.

    So, for example, to jump to the next select element when someone presses the right arrow while on another select element, I'd keep a list of all the select elements on the page; when the right-arrow is pressed, I'd find the position of the currently-focused select in that list, and .focus() the next one.

    0 讨论(0)
提交回复
热议问题