function tip(evt,s){
$('p#vtip').show();
xOffset = -10; // x distance from mouse
yOffset = 10; // y distance from mouse
top = (evt.pageY + yOffset);
left = (evt.pageX + xOffset);
var str = $(s, "> #content").html();
$('p#vtip #content').html(str);
$('p#vtip').css("top", top+"px").css("left", left+"px").fadeIn("slow");
}
In Firefox everything is OK.
However, in Chrome, and Internet Explorer 8, it is always in the bottom:
This is HTML:
<div>
<span onmouseover="tip(event,this);">程序错误<div id="content">good</div></span><br>
<span onmouseover="tip(event,this);">程序错误<div id="content">good</div></span><br>
<span onmouseover="tip(event,this);">程序错误<div id="content">good</div></span><br>
<span onmouseover="tip(event,this);">程序错误<div id="content">good</div></span><br>
<span onmouseover="tip(event,this);">程序错误<div id="content">good</div></span><br>
<span onmouseover="tip(event,this);">程序错误<div id="content">good</div></span><br>
<span onmouseover="tip(event,this);">程序错误<div id="content">good</div></span><br>
<span onmouseover="tip(event,this);">程序错误<div id="content">good</div></span><br>
</div>
<p id="vtip" style="position:absolute"><img id="vtipArrow" src="vtip_arrow.png" />testtest<span class="content"></span></p>
If you’re using jQuery, you may want to take a different approach for your event handling.
First, change
id="content"toclass="content". IDs must be unique, and will cause problems if you refer to them more than once in your HTML. Classes can be used multiple times.Second, if you’re using jQuery, you might as well have it take care of assigning event handlers. Notice that I removed your ‘onmouseover’ statements.
I also gave an ID to the
divthat contains thespans.Next, in your jQuery javascript, assign the ‘mouseover’ event like this:
This will assign the mouseover event to all spans that are a child of #container. You refer back to the element with the handler via ‘this’, or $(this) if you want to use jQuery functions.