Simulate pressing tab key with jQuery

后端 未结 4 1104
不思量自难忘°
不思量自难忘° 2020-12-09 15:14

I have some textboxes on a .net-page and want to achieve the following with jQuery: if the user presses return, the program should behave \"as if\" he had used the tab key,

4条回答
  •  一生所求
    2020-12-09 16:03

    From multiple answers I have combined the perfect solution for me where enter acts as tab on inputs and select and takes focus on next input, select or textarea while allows enter inside text area.

     $("input,select").bind("keydown", function (e) {
         var keyCode = e.keyCode || e.which;
         if(keyCode === 13) {
             e.preventDefault();
             $('input, select, textarea')
             [$('input,select,textarea').index(this)+1].focus();
         }
     });
    

提交回复
热议问题