jquery: Enter to Tab trigger in specific parts
i'm currently having problem in (maybe) a simple programming. i'm quite a newb in jquery
these are my codes:
$(':text').keyup(function(e) {
if(e.keyCode == 13) {
alert('Enter key was pressed.');
$(this).trigger({type: 'k开发者_开发问答eyup', keyCode: 9});
}
});
i've searched almost 20 articles regarding this matter, none of them actually is as simple as this. and here's the problem
the tab key is supposed to replace enter, however, the tab did not trigger. and what i mean by not trigger, is kind of funny in some way. i've tried to change the 9 into 13 (which is the enter itself), and my browser will keep on looping the alert line endlessly, which means that, enter hits another enter, which is triggered by the code below the alert
what do i do wrong? do i have to tell the jquery what to do if keycode 9 is pressed? is there any way to make it trigger as if i hit the keyboard myself?
tyvm before :D any help will be greatly appreciated
Try resetting the focus rather than sending a tab.
$(':text').keydown(function(e) {
if(e.keyCode == 13 && $(this).attr('type') != 'submit') {
e.preventDefault();
$(this).nextAll('input:first').focus();
}
});
精彩评论