jquery:在特定部分中输入Tab触发器 [英] jquery: Enter to Tab trigger in specific parts

查看:60
本文介绍了jquery:在特定部分中输入Tab触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在(可能)一个简单的编程中遇到问题。我是jquery的新手

i'm currently having problem in (maybe) a simple programming. i'm quite a newb in jquery

这些是我的代码:

$(':text').keyup(function(e) {
    if(e.keyCode == 13) {
        alert('Enter key was pressed.');

        $(this).trigger({type: 'keyup', keyCode: 9});
    }
});

我搜索了近20篇关于此事的文章,其中没有一篇真的像这样简单。这就是问题

i've searched almost 20 articles regarding this matter, none of them actually is as simple as this. and here's the problem

tab键应该替换enter,但是,选项卡没有触发。我的意思是不触发,在某种程度上有点滑稽。我试图将9改为13(这是输入本身),我的浏览器将继续无休止地循环警报线,这意味着,输入命中另一个输入,由警报下面的代码触发

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

我做错了什么?如果按下键码9,我必须告诉jquery该怎么办?是否有任何方法让它像我自己敲击键盘一样触发?

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:D任何帮助将不胜感激

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();
    }
});

这篇关于jquery:在特定部分中输入Tab触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆