zoukankan      html  css  js  c++  java
  • 夺命雷公狗---javascript NO:11 事件对象1

    IE模型浏览器下:

    事件对象 =  window.event

    W3C模型浏览器下:

    DOM对象.事件 = function(event) {

    事件对象 = event;

    }

    示例代码:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset=’utf-8′>
    <title></title>
    <script src=’public.js’></script>
    <script>
    window.onload = function(){
    $(‘btnok’).onclick = function(event){
    //IE模型浏览器
    //var event = window.event;
    alert(event);
    }
    }
    </script>
    </head>
    <body>
    <input type=’button’ id=’btnok’ value=”点击”>
    </body>
    </html>

    如何解决兼容性问题

    示例:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset=’utf-8′>
    <title></title>
    <script src=’public.js’></script>
    <script>
    window.onload = function(){
    $(‘btnok’).onclick = function(event){
    if(window.event){
    alert(window.event);
    }else{
    alert(event);
    }
    }
    }
    </script>
    </head>
    <body>
    <input type=’button’ id=’btnok’ value=”点击”>
    </body>
    </html>
  • 相关阅读:
    用VisualSVN做项目版本控制
    jQuery 停止动画
    jQuery 效果
    jQuery 效果
    jQuery 效果
    jQuery 事件
    jQuery 选择器
    jQuery 语法(一)
    Form.ShowWithoutActivation 属性
    C#里面中将字符串转为变量名
  • 原文地址:https://www.cnblogs.com/leigood/p/5031859.html
Copyright © 2011-2022 走看看