这段代码获得鼠标的位置,但是如果网页有滚动条的话,获得的鼠标位置就不对了
<script language= "javascript ">
var xCoord=0
var yCoord=0
var where = " "; // which link
function checkwhere(e) {
if (document.layers){
xCoord = e.x;
yCoord = e.y;
}
else if (document.all){
xCoord = event.clientX;
yCoord = event.clientY;
}
else if (document.getElementById){
xCoord = e.clientX;
yCoord = e.clientY;
}
}
</script>
------解决方案--------------------加上滚动偏移:
document.body.scrollLeft
document.body.scrollTop