简体   繁体   English

禁用在“表单提交”上输入Enter键并将其更改为选项卡

[英]Disable Enter Keypress on Form Submit & Change it into a tab instead

Disable Enter Keypress on Form Submit & Change it into a tab instead 禁用在“表单提交”上输入Enter键并将其更改为选项卡

How do I disable the key "enter keydown" on form submit button, because in a form, when I press "enter", it will submit my form. 我如何在表单提交按钮上禁用键“ enter keydown”,因为在表单中,当我按下“ enter”时,它将提交我的表单。

I want my enter to become "tab" instead, so when I press enter eg at 我希望我的输入改为“ tab”,所以当我按Enter时,例如

input text id="text_1", i want maybe change it focus to "small_1" (another textfield) , then if I press enter again at small_1, I want change it focus to big_1 输入text id =“ text_1”,我想将其焦点更改为“ small_1”(另一个文本字段),然后如果我再次在small_1处按Enter,我希望将其焦点更改为big_1

and so on 等等

How do I achieve this, I tried jquery autotab but it doesn't work like what I wanted. 我如何做到这一点,我尝试了jquery autotab,但是它不能按照我的要求工作。

Add a method to watch for the enter key being pressed (using jQuery): 添加一个方法来监视按下输入键(使用jQuery):

("#text_1").bind("keyup keypress", function(event){
    var code = event.keyCode || event.which; 
      if (code == 13)  {
          event.preventDefault();
          $('html, body').animate({
              scrollTop: $("#small_1").offset().top
          }, 2000);
          return false;
      }
});

("#small_1").bind("keyup keypress", function(event){
      var code = event.keyCode || event.which; 
      if (code == 13)  {
          event.preventDefault();
          $('html, body').animate({
              scrollTop: $("#big_1").offset().top
          }, 2000);
          return false;
      }
});

You could set these up with JavaScript to detect the elements (and generate strings for the ids in a for loop) so you don't have to do these for each one, and it would also make it easier to add new ones. 您可以使用JavaScript设置这些元素以检测元素(并在for循环中为id生成字符串),因此不必为每个元素都做这些,这也将使添加新元素变得更加容易。

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

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