Enter key press behaves like a Tab in Javascript

后端 未结 22 1293
说谎
说谎 2020-11-27 10:52

I\'m looking to create a form where pressing the enter key causes focus to go to the \"next\" form element on the page. The solution I keep finding on the web is...

22条回答
  •  感动是毒
    2020-11-27 11:24

    I've had a similar problem, where I wanted to press + on the numpad to tab to the next field. Now I've released a library that I think will help you.

    PlusAsTab: A jQuery plugin to use the numpad plus key as a tab key equivalent.

    Since you want enter/ instead, you can set the options. Find out which key you want to use with the jQuery event.which demo.

    JoelPurra.PlusAsTab.setOptions({
      // Use enter instead of plus
      // Number 13 found through demo at
      // https://api.jquery.com/event.which/
      key: 13
    });
    
    // Matches all inputs with name "a[]" (needs some character escaping)
    $('input[name=a\\[\\]]').plusAsTab();
    

    You can try it out yourself in the PlusAsTab enter as tab demo.

提交回复
热议问题