zoukankan      html  css  js  c++  java
  • js小技巧

    1.判断当前js环境是否为严格模式

    //定义并调用一个函数来确定当前脚本运行时是否为严格模式
    var strict = (function() { return !this; })();

     2.检测一个对象是否是真正的函数对象

    function isFunction(x) {
    return Object. prototype. toString.call(x) === "[object Function]' ;
    }

    3.低版本不兼容e.preventDefault()和e.target

    //获取事件对象
    var getEvent = function (event) {
        //标准浏览器返回event, IE下window. event
        return event || window. event ; 
    }
    //获取元素!
    var getTarget = function (event) {
        var event = getEvent (event) ;
        //标准浏览器下event.target, IE下event.srcElement
        return event.target || event.srcElement;
    }
    //阻止默认行为
    var preventDefault = function (event) {
        var event = getEvent (event) ;
        //标准浏览器
        if (event.preventDefault) {
            event.preventDefault () ;
        // IE浏览器
        }else {
            event. returnValue = false;
        }
    }
  • 相关阅读:
    P4297 [NOI2006]网络收费
    P4207 [NOI2005]月下柠檬树
    bzoj2517 矩形覆盖
    bzoj2506 calc
    ......
    SP1811 LCS
    CF585E Present for Vitalik the Philatelist
    好康的
    CF605E Intergalaxy Trips
    字符串
  • 原文地址:https://www.cnblogs.com/LeoXnote/p/13048712.html
Copyright © 2011-2022 走看看