简体   繁体   中英

jquery Enter as Tab is not working in Firefox but working fine in Chrome

I have made this script below is working fine in chrome by the help of someone in stackoverflow.

(function($) {
$.fn.enterAsTab = function(options) {
    var settings = $.extend({
        'allowSubmit': false
    }, options);
    $(this).find('input, select, textarea, button').on("keypress", {localSettings: settings}, function(event) {
        if (settings.allowSubmit) {
            var type = $(this).attr("type");
            if (type == "submit") {
                return true;
            }
        }
        if (event.keyCode == 13) {
            var inputs = $(this).parents("form").eq(0).find(":input:visible:not(:disabled):not([readonly])");
            var idx = inputs.index(this);
            if (idx == inputs.length - 1) {
                idx = -1;
            } else {
                inputs[idx + 1].focus(); // handles submit buttons
            }
            try {
                inputs[idx + 1].select();
            }
            catch (err) {
                // handle objects not offering select
            }
            return false;
        }
    });
    return this;
};

})(jQuery);

But this code is not fully working in Firefox. The not working part is the select. I cannot use enter to move to next field when I am in a dropdown (Select).

Thank you in advance.

event.keycode is not supported by Firefox. You need to use event.which for Firefox.

Take a look: window.event.keyCode how to do it on Firefox?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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