如何将Enter键转换为Tab键按网页 [英] How to Convert An Enter Key Press Into A Tab Key Press For Web Pages

查看:230
本文介绍了如何将Enter键转换为Tab键按网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Enter键应该像Tab键一样工作.TextArea和Submit Button的Enter键应该像往常一样工作.当下一个字段被禁用/只读时,焦点应该从下一个元素跳过.

谢谢

解决方案

首先,在可用性方面这可能不是一个好主意.但是,这应该可行:

$(":input").on("keydown", function(event) {
    if (event.which === 13 && !$(this).is("textarea, :button, :submit")) {
        event.stopPropagation();
        event.preventDefault();

        $(this)
            .nextAll(":input:not(:disabled, [readonly='readonly'])")
            .first()
            .focus();
    }
});

示例: http://jsfiddle.net/NDcrk/

找到下一个输入的内容可能必须更改,具体取决于您的标记.

The enter key press should work like a Tab key press.The enter key press for TextArea and Submit Button should work as usual.Focus should skip from the next element when the next field is disabled/readonly.

thanks,

解决方案

First off, this is probably not a great idea usability-wise. However, here's something that should work:

$(":input").on("keydown", function(event) {
    if (event.which === 13 && !$(this).is("textarea, :button, :submit")) {
        event.stopPropagation();
        event.preventDefault();

        $(this)
            .nextAll(":input:not(:disabled, [readonly='readonly'])")
            .first()
            .focus();
    }
});

Example: http://jsfiddle.net/NDcrk/

The piece that finds the next input may have to change, depending on your markup.

这篇关于如何将Enter键转换为Tab键按网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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