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页面失去焦点,动态删除element


下一篇:合并两个ColorMatrix或在Imageview上同时应用两个或多个ColorMatrix