zoukankan      html  css  js  c++  java
  • Discuz common.js代码注释(二)

    //获取浏览器版本号
    function browserVersion(types) {
        var other = 1;    //默认版本号
        for (i in types) {  //遍历types
            var v = types[i] ? types[i] : i; //判断types[i]是否为空,为空给types[i]赋值为i(types循环出的键),不为空则赋值types[i]本身
            if (USERAGENT.indexOf(v) != -1) {  //USERAGENT:浏览器请求头的User-Agent属性
                var re = new RegExp(v + '(\/|\s|:)([\d\.]+)', 'ig');  //声明正则表达式
                var matches = re.exec(USERAGENT);    //在USERAGENT匹配符合正则表达式的结果集
                var ver = matches != null ? matches[2] : 0;  //得到版本号
                other = ver !== 0 && v != 'mozilla' ? 0 : other;//如果ver不等于0且v不是火狐浏览器若为空则默认版本号,不为空则返回0
              } else {
                var ver = 0;   //设置版本号为0 
            }
            eval('BROWSER.' + i + '= ver'); //执行表达式
        }
        BROWSER.other = other;  //设置非标准浏览器版本号
    }
    //获取事件对象
    function getEvent() { 
        if (document.all) return window.event;   //document.all:指页面所有元素的集合(只有IE支持) 返回值window.event:指事件对象(只有IE支持)
        func = getEvent.caller;   //获取调用getEvent函数caller func可能的结果:类似function onclick(event){}这样的方法函数本体
        while (func != null) {    //遍历func,通过dfunc.arguments[0]获取到函数的第一个参数(event事件对象),如果事件对象为空,则通过func=func.caller重新给func赋值,直到取到满足条件的event事件对象
            var arg0 = func.arguments[0];  //获取触发本函数(getEvent)函数的第一个参数
            if (arg0) {
                //arg0.constructor:          constructor可能是Event也可能是MouseEvent
                //typeof (arg0) == "object": 判断arg0是否为对象
                //arg0.preventDefault:      判断preventDefault方法是否存在(preventDefault()的作用只要是通知web浏览器不要执行与事件关联的默认动作)
                //arg0.stopPropagation:      判断stopPropagation方法是否存在(stopPropagation()的作用是停止事件的传播,阻止它被分派到其他Document节点)
                if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
                    return arg0;   //返回arg0
                }
            }
            func = func.caller;    //将func的caller赋值给func
        }
        return null;  //返回null
    }
    //判断参数值的变量类型是否等于‘undefined’如果等于就返回true,否则返回false
    function isUndefined(variable) {  
        return typeof variable == 'undefined' ? true : false;
    }
    //判断needle是否存在于haystack数组中
    function in_array(needle, haystack) {   //needle:指定值 haystack:数组集合
        if (typeof needle == 'string' || typeof needle == 'number') {    //判断变量needle的数据类型
            for (var i in haystack) {    //遍历haystack
                if (haystack[i] == needle) {  //判断haystack中是否有值等于needle
                    return true;    //如果有则返回true
                }
            }
        }
        return false;    //如果haystack中没有值等于needle就返回false
    }
    
    
     
    
  • 相关阅读:
    【转】CUDA5/CentOS6.4
    【转】centos 6.4 samba 安装配置
    【转】Install MATLAB 2013a on CentOS 6.4 x64 with mode silent
    【转】Getting xrdp to work on CentOS 6.4
    【VLFeat】使用matlab版本计算HOG
    Unofficial Windows Binaries for Python Extension Packages
    March 06th, 2018 Week 10th Tuesday
    March 05th, 2018 Week 10th Monday
    March 04th, 2018 Week 10th Sunday
    March 03rd, 2018 Week 9th Saturday
  • 原文地址:https://www.cnblogs.com/love-is/p/4289398.html
Copyright © 2011-2022 走看看