Window.Event 多浏览器兼容
程序员文章站
2022-04-28 09:10:33
...
//tip show function showTip(boxID,tipText,evt){ //方法中必须传event作为参数,FF下根据window.event获取对象 var evt = (evt) ? evt : ((window.event) ? window.event : null); var content=document.getElementById(boxID); content.innerHTML = tipText; content.style.display="block"; var x=document.documentElement.scrollLeft + evt.x; var y=document.documentElement.scrollTop + evt.clientY ; content.style.left = x + "px"; content.style.top = y + "px"; } //tip hide function hideTip(boxID){ var content=document.getElementById(boxID); content.style.display="none"; }
<div id="text" onmouseover="showTip('tipBox','Show Tip Box!',event)" onmouseout="hideTip('tipBox')" >
Show Tip Box
</div>
<p>this para1</p><p>this para2</p>
<p>this para1</p><p>this para2</p>
<div id="tipBox" style="position:absolute;">
</div>