开发者

Move focus from one control to another control just pressing enter key by Jquery

开发者 https://www.devze.com 2023-02-04 19:33 出处:网络
suppose i have many html control in the page and all the control has a sequentially tab stop set.so if i press tab then focus move properly but i want to mo开发者_C百科ve focus just by pressing enter

suppose i have many html control in the page and all the control has a sequentially tab stop set.so if i press tab then focus move properly but i want to mo开发者_C百科ve focus just by pressing enter key instead of tab. so please tell me how could i programatically press tab when user will press enter key in my web page just by javascript or jquery. expecting small smaple code to achieve the effect i need.

thanks.


$(':input').keypress(function(e){
  if(e.which == 13){
    ti = $(this).attr('tabindex') + 1;
    $('input[tabindex='+ti+']').focus();
    //try to use________ e.which = 9; return e.which;
  }else if(e.which == 9){
    e.preventDefault(); //or return false;
  }
});

Javascript way:

<body onkeydown="if(event.keyCode==13){event.keyCode=9; return event.keyCode;}">
0

精彩评论

暂无评论...
验证码 换一张
取 消