.focus() “set focus on a target input” will not work in Firefox

回眸只為那壹抹淺笑 提交于 2019-12-04 18:04:48

As you are using jQuery should use the .focusout() method.

http://api.jquery.com/focusout/

This is distinct from the blur event in that it supports detecting the loss of focus from parent elements (in other words, it supports event bubbling).

I was able to resolve my situation by avoiding my question above.

Since I am dealing with the Tab key, instead of trying to place the focus back in the field that the user tabbed out of (like my attempt above), I used preventDefault() on the Tab key. Therefore focus is never lost, and I don't have to worry about replacing it.

displayTextBox.keydown
(
    function(event)
    {           
        // 9 = Tab Key
        if (event.keyCode == "9")
        {
            event.preventDefault();
        }
    }
);

I have not thoroughly tested this, but it seems to work so far in FF, Chrome and IE.

Try to use the html attribute onfocusout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!