其他分享
首页 > 其他分享> > js基础---event事件对象 解决IE8兼容性问题 练习(1)

js基础---event事件对象 解决IE8兼容性问题 练习(1)

作者:互联网

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style type="text/css">
                #areaDiv {
                    border: 1px solid black;
                    width: 300px;
                    height: 50px;
                    margin-bottom: 10px;
                }
                
                #showMsg {
                    border: 1px solid black;
                    width: 300px;
                    height: 20px;
                }
        </style>
        
        <script type="text/javascript">
            window.onload = function(){
                document.querySelector("#areaDiv").onmousemove = function(event){
                    event = event || window.event;
                    
                    // 正常浏览器时传参获取event对象  IE8的even对象在window中所以使用 window.event
                    document.querySelector("#showMsg").innerHTML = "X: "+event.clientX+" Y: "+event.clientY;
                }
            }
        </script>
    </head>
    <body>
            <div id="areaDiv"></div>
            <div id="showMsg"></div>
    </body>
</html>

 

标签:IE8,height,width,window,兼容性问题,js,border,event
来源: https://www.cnblogs.com/leiyanting/p/15229821.html