:悬停属性不适用于Firefox / IE

时间:2016-04-21 00:37:33

标签: javascript jquery html css

当鼠标悬停在桌子上的某个字段上时,我会在该字段中添加div并在新添加的字段中显示一些文本(工具提示)。当我将鼠标悬停在表格区域时,我希望它被关闭,但我希望它保持打开状态,只要我在它的子元素(新添加的div)中。它适用于Chrome,但不适用于FF / IE

$(document).ready(init);

function init(){
  $('table td.column_5').on('mouseover', show_tooltip);
  $('.tooltip, table td.column_5').on('mouseout',remove_tooltip);
}
function show_tooltip(e){
    if ($(e.target).text() !== '' && !$(this).children().hasClass('tooltip')){
        var tooltip = '<div class="tooltip">'+$(e.target).text()+'</div>';
        $(this).append(tooltip);
    }
}
function remove_tooltip(e){
  if ($(this).children().hasClass('tooltip') && !$(this).children('.tooltip').is(':hover')){
    $('.tooltip').remove();
}

2 个答案:

答案 0 :(得分:3)

好的,我仔细看了一下。请立即删除downvote :)这里出了什么问题。

function remove_tooltip(e) {
  if ($(this).children().hasClass('tooltip') && !$(this).children('.tooltip').is(':hover'){
    $('.tooltip').remove();
}

你错过了结束)和结束}例如使用下面的代码

$(document).ready(init);

function init(){
  $('table td.column_5').on('mouseover', show_tooltip);
  $('.tooltip, table td.column_5').on('mouseout',remove_tooltip);
}
function show_tooltip(e){
    if ($(e.target).text() !== '' && !$(this).children().hasClass('tooltip')){
        var tooltip = '<div class="tooltip">'+$(e.target).text()+'</div>';
        $(this).append(tooltip);
    }
}
function remove_tooltip(e) {
  if ($(this).children().hasClass('tooltip') && !$(this).children('.tooltip').is(':hover')){
    $('.tooltip').remove();
  }
}

答案 1 :(得分:1)

我找到了办法!以下是我的进展:

List<Task<>>