首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

DOM中的有关问题,为什么新建的<div>层的坐标不是鼠标的位置,求高手解释

2013-02-24 
DOM中的问题,为什么新建的div层的坐标不是鼠标的位置,求高手解释headtitle/titlescript typete

DOM中的问题,为什么新建的<div>层的坐标不是鼠标的位置,求高手解释
<head>
    <title></title>
    <script type="text/javascript">
        function initEvent() {
            var as = document.getElementsByTagName("a");
            for (var i = 0; i < as.length; i++) {
                var a = as[i];
                a.onmouseover = aMouseOver;
            }
        }
        function aMouseOver() {
            //动态创建一个层;
            var div = document.createElement("div");
            div.style.position ="absolute";
            div.style.top = window.event.clientY;
            div.style.left = window.event.clientX;
            div.innerHTML = "测试";

            document.body.appendChild(div);//放到body中
        }
    </script>
</head>
<body onload="initEvent()">
<a href="http://www.baidu.com" >百度</a><br /><br />
<a href="http://www.baidu.com" >百度</a><br /><br />
<a href="http://www.baidu.com" >百度</a><br /><br />
</body>


为什么新建的<div>层的坐标不是鼠标的位置,求高手解释div.style.top = window.event.clientY;
            div.style.left = window.event.clientX;
[解决办法]
Sets or retrieves the x-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.


用screenX,screenY试试看吧

热点排行