简体   繁体   English

工具提示 (title="...") 不会在 Firefox 中显示

[英]Tooltips (title="...") won't show in Firefox

I have an element with a title attribute (ie, a tooltip), wrapped in some container:我有一个带有title属性的元素(即工具提示),包装在某个容器中:

<div id="foo">
    <input type="text" title="A tooltip" />
</div>

and I attach a "mousemove" event listener on the container and stop event propagation:我在容器上附加了一个"mousemove"事件监听器并停止了事件传播:

document.getElementById('foo').addEventListener(
    'mousemove',
    function(e) { e.stopPropagation() },
    false
)

This combination of stopping propagation of "mousemoves" on the container now prevents the tooltip from showing up for the inner textbox, in Firefox 2 and upwards.在 Firefox 2 及更高版本中,这种停止在容器上传播“mousemoves”的组合现在可防止工具提示显示在内部文本框上。 I've tried FF 2[.0.0.20], 3[.0.11], and the latest 3.5 (Windows Server 2003, XP).我试过 FF 2[.0.0.20]、3[.0.11] 和最新的 3.5(Windows Server 2003、XP)。

As a quick exercise, Firefox users can see this bug in action by running the following equivalent logic as above in your address bar:作为快速练习, Firefox用户可以通过在您的地址栏中运行以下与上面相同的逻辑来实际查看此错误:

javascript:void($('div.vote').mousemove(function(e){ e.stopPropagation() }))

Now mouseover any of the vote up, vote down, or star (favorites) icons for this question.现在将鼠标悬停在该问题的任何赞成票、反对票或星号(收藏夹)图标上。 The tooltips no longer appear.工具提示不再出现。 Again, in Firefox only .同样,仅在 Firefox 中

Does anyone have a workaround for this behavior/bug in Firefox? Firefox 中是否有人有解决此行为/错误的方法? Has anyone else witnessed this?还有其他人目睹过这个吗?

Update : It appears Firefox uses "mouse stopped moving" to trigger tooltips in the browser chrome (eg back/forward buttons).更新:Firefox 似乎使用“鼠标停止移动”来触发浏览器 chrome 中的工具提示(例如后退/前进按钮)。 See https://bugzilla.mozilla.org/show_bug.cgi?id=82953 .请参阅https://bugzilla.mozilla.org/show_bug.cgi?id=82953 However I can't tell if this affects the DOM.但是我不知道这是否会影响 DOM。

Update : It appears Firefox 10 was the last version exhibiting this behavior.更新:似乎 Firefox 10 是展示此行为的最后一个版本。 Firefox 11.0 and onwards shows tooltips regardless of event propagation. Firefox 11.0 及更高版本显示工具提示,无论事件传播如何。

Update : Firefox 33(.1) no longer exhibits this behavior.更新:Firefox 33(.1) 不再表现出这种行为。

I've confirmed this issue.我已经确认了这个问题。 I even tried propagating the event by hand to only the input box using this code:我什至尝试使用以下代码手动将事件传播到输入框:

<div id="foo" title="A tooltip 2"> <input title="A tooltip" type="text" id="bar"/>
</div>
<script type="text/javascript">
document.getElementById('foo').addEventListener(
    'mouseover',
    function(e) {
        e.stopPropagation();
        if (document.createEvent) {
            var inputBox = document.getElementById('bar');
            var evt = document.createEvent("MouseEvents");
            evt.initMouseEvent("mousemove", true, true, window, e.detail, e.screenX, e.screenY, e.clientX, e.clientY, false, false, false, false, null, null);
            inputBox.dispatchEvent(evt);
        }
    },
    false
)
</script>

No dice.没有骰子。 However, other mouse events, including mouseover, seem to work fine.但是,其他鼠标事件(包括鼠标悬停)似乎工作正常。

I believe this is a bug.我相信这是一个错误。 Although it isn't listed in bugzilla, a search does seem to indicate a correlation between the event "mouseover" and tooltips.虽然它没有在 bugzilla 中列出,但搜索似乎确实表明事件“鼠标悬停”和工具提示之间存在关联

You might download the latest nightly build of Firefox here and see if it still is there.您可以在此处下载 Firefox 的最新夜间版本,看看它是否仍然存在。 If it is, file a bug .如果是,请提交错误

As an alternative, I would see if mouseover might give you the desired effect.作为替代方案,我会看看鼠标悬停是否会给您带来预期的效果。

I recently read that some firefox addOns (ie google toolbar) result in problems with the title-tooltips.我最近读到一些 firefox 插件(即谷歌工具栏)导致标题工具提示出现问题。 Deactivate them and check if this solves your issue.停用它们并检查这是否可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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