在我的.Net网络应用程序中,我有一些“skmTooltipHost”类的元素,它们是动态放置在页面上的。我的JQuery show()在IE中工作,但不是FF?
当鼠标悬停在它们上面时,应显示一个工具提示类型的弹出窗口。这在IE中完美运行,但在Firefox中完全没有。
请帮忙!
其中,那么 “悬停和Show”
$(document).ready(function() {
$(".skmTooltipHost").hover(function() {
$(this).empty().append('<div class="skmTooltipContainer"><strong>hello</strong>' + $(this).attr('tooltip') + '</div>');
$(this).find('.skmTooltipContainer').css("left", $(this).position().left + 20);
$(this).find('.skmTooltipContainer').css("top", $(this).position().top + $(this).height());
$(".skmTooltipContainer").css("display", "inline-block");
$(".skmTooltipContainer").show();
$(this).show();
},function() {
$(".skmTooltipContainer").fadeTo(500, 1.0, function() { $(this).remove(); });
});
});
我的CSS
.skmTooltipHost
{
cursor: help;
border-bottom: dotted 1px brown;
}
.skmTooltipContainer
{
padding-left: 10px;
padding-right: 10px;
padding-top: 3px;
padding-bottom: 3px;
display:inline-block;
position: absolute!important;
background-color: #ff9;
border: solid 1px #333;
z-index: 999;
}
编辑
我终于用一组不同但相似的代码做的JavaScript工作。我不确定有什么不同。我的工作代码如下:
function simple_tooltip(target_items, name) {
$(target_items).each(function (i) {
$("body").append("<div class='" + name + "' id='" + name + i + "'><p>Click for a link to the run details</br><strong>Server: </strong>" + $(this).attr('title') + "</br><strong>Information:</strong>" + $(this).attr('error') + "</p></div>");
var my_tooltip = $("#" + name + i);
$(this).removeAttr("title").mouseover(function() {
my_tooltip.css({ opacity: 0.8, display: "none" }).fadeIn(100);
}).mousemove(function (kmouse) {
my_tooltip.css({ left: kmouse.pageX + 15, top: kmouse.pageY + 15 });
}).mouseout(function() {
my_tooltip.fadeOut(100);
});
});
}
$(document).ready(function() {
simple_tooltip($(".skmTooltipHost"), "tooltip");
});
.tooltip{
position:absolute;
z-index:999;
left:-9999px;
background-color:#dedede;
padding:2px;
border:1px solid #fff;
width:250px;
}
.tooltip p{
margin:0;
padding:0;
color:black;
background-color:white;
padding:2px 7px;
}
其实这两行现在什么都不做,我只是加了它们去试试。它们似乎没有影响功能。仍然适用于IE。不在FF中。 $(“。skmTooltipContainer”).css(“display”,“inline-block”); $(this).show(); – mplace 2013-03-12 10:00:56
您是否尝试将定位添加到'.skmTooltipHost'(例如'position:relative;')? – MassivePenguin 2013-03-12 10:03:18
尝试使用'.on'来触发'hover'。 – Red 2013-03-12 10:07:14