Firefox奇怪的onblur行为(3.6.12) [英] Firefox weird onblur behavior (3.6.12)

查看:134
本文介绍了Firefox奇怪的onblur行为(3.6.12)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此处查看测试页 http://rickchristie.com/testfocus.html

如果我错了,请纠正我的错误:


  1. <$当元素获得焦点时,c $ c> onfocus 会发生。
  2. 焦点。

在Firefox 3.6.12(在Mac和Windows上测试)中,使用 onblur 没有 onfocus 工作正常。然而,当一个input元素 onfocus onblur 元素时,它会变得奇怪:


  1. 在输入处点击 onblur 而不是 onfocus

  2. 恰好在 onblur 之后, onfocus














    $ b 其他浏览器(Safari,Opera)按预期工作。这是一个错误?是只是我还是每个人都使用Firefox体验这一点?



    更新



    这种行为似乎只发生在 onblur onfocus 包含 alert - 不是当我用 window.log

    解决方案

    警告框打开时,焦点从文本框中删除。请注意,BLUR警告框在FOCUS警告框(后者首先打开)的顶部打开,所以这就是为什么它看起来像 onblur 在<$之前c $ c> onfocus



    看看我的测试页面,当任何一个事件处理程序被调用时增加一个计数器,并且在其他两个之后增加第二个提醒框。尽管浏览器的概念上是单线程模型,但Firefox一旦从焦点处理程序中的警告框打开,Firefox实际上就开始执行模糊处理程序。但是,当第一个(焦点)警报框关闭时,第二个(模糊)警报框也必须在第三个(焦点之后)警报框打开之前关闭。



    我不知道Firefox为什么这样做。 Chrome会一次又一次地触发焦点处理程序,Opera,Safari和IE会按照您所期望的方式执行操作。没有拿走文本框的焦点。



    编辑:我找到 https://bugzilla.mozilla.org/show_bug.cgi?id=31889 ,并将在此发布此测试用例。显然它曾经更糟。

    Check the test page here http://rickchristie.com/testfocus.html

    Correct me if I'm wrong:

    1. onfocus happens when the element gains focus.
    2. onblur happens when the element loses the focus.

    In Firefox 3.6.12 (tested on mac and windows), using onblur without onfocus works fine. However when an input element has both onfocus and onblur element, it gets weird:

    1. When you click at the input, onblur is fired instead of onfocus.
    2. Right after onblur, onfocus fires immediately.
    3. You can't type anything in the textbox.

    Other browsers (Safari, Opera) works as expected. Is this a bug? Is it just me or is everybody using Firefox experiencing this?

    Update

    This behavior seems to happen only when onblur and onfocus contains alert - not when I use something like window.log.

    解决方案

    When the alert box opens, focus is removed from the text box. Notice that the "BLUR" alert box opens right on top of the "FOCUS" alert box (the latter opened first), so that's why it looks like onblur fired before onfocus.

    Look at my test page, which increments a counter when either event handler is called and also adds a second alert box after both of the others. It seems that Firefox actually starts executing the blur handler as soon as the alert box from the focus handler opens, despite the conceptually single-threaded model of the browser. However, when the first (focus) alert box is closed, the second (blur) alert box has to also be closed before the third (after focus) alert box opens.

    I don't know Firefox why does it the way it does. Chrome keeps firing the focus handler again and again, and Opera, Safari, and IE do it the way you would expect — not taking away the text box's focus.

    EDIT: I've found https://bugzilla.mozilla.org/show_bug.cgi?id=31889 and will be posting this test case there – apparently it used to be even worse.

    这篇关于Firefox奇怪的onblur行为(3.6.12)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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