<!DOCTYPEhtml>
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<title>jquery获取鼠标指针的坐标</title>
<script>
//普通js函数
functiontest(event){
event=event||window.event;
varx=event.offsetX||event.layerX;
vary=event.offsetY||event.layerY;
alert("x="+x+";y="+y);
}
//jquery函数
$(function(){
$("#t").mouseover(
function(event){
event=event||window.event;
varx=event.offsetX||event.originalEvent.layerX;
vary=event.offsetY||event.originalEvent.layerY;
alert("x:"+x+";y:"+y);
}
);
});
</script>
</head>
<body>
<divid="t"style="float:left;background-color:green;width:300px;height:60px;">测试鼠标位置(jquery函数处理)</div>
<divid="s"onmouseover="test(event)"style="float:left;background-color:red;width:300px;height:60px;margin-left:10px;">测试鼠标位置(普通js函数处理)</div>
</body>
</html>