javascript - IE8 在悬停选择框的选项时中断

标签 javascript jquery hover html-select

好的,所以我有以下代码,在除 IE 之外的所有浏览器中都可以正常工作。

$('input[title!=], select[title!=]').mouseenter(function(){
    if ($(this).data('focused')!='y') {
        $(this).data('t', this.title).data('focused', 'y');
        this.title = '';
        var pos = $(this).position();
        $('body').append('<div id="toolTip" class="round-5 shadow-heavy"><img class="arrow" src="/images/bg/toolTip.png" alt="" />'+($(this).data('t'))+'</div>');
        $('#toolTip').css('top',(pos.top+($(this).height()/2)-($('#toolTip').innerHeight()/2))+'px').css('left',(pos.left+($(this).innerWidth())+20)+'px'); 
    }
}).mouseleave(function(){
    if ($(this).data('focused')!='n') {
        $(this).data('focused', 'n');
        this.title = $(this).data('t');
        $('#toolTip').remove();
    }
}).focus(function(){if($(this).data('focused')!='y'){$(this).trigger('mouseenter');}}).blur(function(){if($(this).data('focused')!='n'){$(this).trigger('mouseleave');}});  

现在,在 IE 中,如果您打开选择框并将鼠标移到选择框关闭的选项之一上。导致它的原因是 IE 显然没有将选项的下拉框计为选择元素的一部分,因此它触发了 mouseleave 事件。

有人知道解决这个问题的方法吗?

最佳答案

IE 对 <select> 的实现非常特别奇怪,因为 IE6(可能更早)它是从 winforms 中拉进来的......这也是它位于除 <iframe> 之外的任何东西之上的原因。在旧版本中。

不幸的是,关于或涉及 <option> 的事件元素充其量是不可靠的(就像你看到的那样)......并且在 IE 中不可信。您可以在 IE 中禁用该行为,但这是唯一的“修复”。

全面替代方案是替换 <select>完全可以,有一些 jQuery 插件可以做到这一点,check out this question for options around that .

关于javascript - IE8 在悬停选择框的选项时中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4444216/

相关文章:

php - 针对我的特定情况将数据从 PHP 传递到 JavaScript 的最佳方式

javascript - 数字中的前导和尾随零

jquery - 这个切换按钮如何通过 CSS 工作?

javascript - 尝试通过将鼠标悬停在一个 div 上来向多个 div 添加类

html - a 标签内的不同悬停行为。 IE 8+ 中的问题

jquery - 如何在触摸设备上模拟悬停效果?

javascript - 在 Firebase 函数中按 documentId 查询

javascript - 用函数(变量)替换变量

javascript - 为什么 attr() 给了我一个奇怪的结果?

javascript - jQuery 事件处理逻辑