/*
<div id="div_show"
style="height:38px;width:150px;position:absolute;
z-index:10;background-color:#123123;left:-10px;top:-10px" >
显示坐标的 div
</div>
*/
function showMousePosition()
{
var x=document.body.scrollLeft+event.clientX;
var y=document.body.scrollTop+event.clientY;
var strposition=x+":"+y;
var obj= document.getElementById("div_show");
obj.innerHTML=strposition;
obj.style.left=parseInt(x)-parseInt(obj.style.width.replace('px',''));
obj.style.top=parseInt(y)-parseInt(obj.style.height.replace('px',''));
obj.style.backgroundColor="#AAAAAA";
obj.style.fontSize="38px";
}
本文介绍了一个简单的JavaScript函数,用于实时显示鼠标在网页上的位置坐标。通过修改div元素的样式和内容来实现这一功能,同时调整了背景颜色和字体大小以提高可见性。
1411

被折叠的 条评论
为什么被折叠?



