<style type="text/css">
body { margin:0px; }
.map { width:100px; height:100px; position:absolute; background-color:#476D78; position:absolute; top:200px; left:500px; }
</style>
<script type="text/javascript">
document.onmousedown=function(){
// 获取当前div的坐标
var div=document.getElementById("mydiv");
var top,left;
if(div.currentStyle){left=div.currentStyle.left;top=div.currentStyle.top;}
else if(window.getComputedStyle){left=window.getComputedStyle(div,null).left;top=window.getComputedStyle(div,null).top;}
alert(left+","+top);
}
</script>
<div class="map" id="mydiv">
asdfasdfasdfasdf
</div>
获取div的页面位置
最新推荐文章于 2023-02-01 16:34:48 发布