<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>7777777</title>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script type="text/javascript">
//方法1
function mousePos(e){
var x,y;
var e = e||window.event;
return {
x:e.clientX+document.body.scrollLeft + document.documentElement.scrollLeft,
y:e.clientY+document.body.scrollTop + document.documentElement.scrollTop
};
};
//方法2
//Firefox支持属性pageX,与pageY属性,这两个属性已经把页面滚动计算在内了,
//在Chrome可以通过document.body.scrollLeft,document.body.scrollTop计算出页面滚动位移,
//而在IE下可以通过document.documentElement.scrollLeft ,document.documentElement.scrollTop
function getMousePos(event) {
var e = event || window.event;
var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
var x = e.pageX || e.clientX + scrollX;
var y = e.pageY || e.clientY + scrollY;
//alert(‘x: ‘ + x + ‘\ny: ‘ + y);
return { ‘x‘: x, ‘y‘: y };
}
function test(object,zhi,e){
//document.getElementById("mjs").innerHTML = getMousePos(e).x+‘,‘+getMousePos(e).y;
$("#mydiv1").css("top", getMousePos(e).y+10+"px").css("left", getMousePos(e).x+"px").css("display", "block");
$("#mydiv1").html(zhi);
};
function hides(object){
//document.getElementById("mjs").innerHTML = getMousePos(e).x+‘,‘+getMousePos(e).y;
$("#mydiv1").css("display", "none");
$("#mydiv1").html("");
};
</script>
<style type="text/css">
.tip {
width:200px;
border:2px solid #ddd;
padding:8px;
background:#f1f1f1;
color:#666;
}
</style>
</head>
<body>
<button>点击我</button>
<div id="x">我会变红的哦</div>
<div id="mydiv1" style="position:absolute;display:none;border:1px solid silver;background:silver;">
提示1效果
</div>
<div id="mydiv2" style="position:absolute;display:none;border:1px solid silver;background:silver;">
提示2效果
</div>
<a id="t1" onMouseOver="test( this,‘终于找到了‘,event)" onMouseOut="hides(this)">鼠标放上去1</a>
<br><br><br><br><br>
<a id="t2" onMouseOver="test(this,‘ok‘,event)" onMouseOut="hides(this)">鼠标放上去2</a>
</body>
</html>