• javascript语言精粹-笔记


    walkDOM

    function walkTheDOM(node, func) {
        func(node); 
        node = node.firstChild; 
        while (node) { 
            walkTheDOM(node, func); 
            node = node.nextSibling; 
        } 
    } 
    
    

    getElementsByClassName

    function getElementsByClassName(className) { 
        var results = []; 
        walkTheDOM(document.body, function (node) { 
            var a, c = node.className, i; 
            if (c) { 
                a = c.split(' '); 
                for (i = 0; i < a.length; i += 1) { 
                    if (a[i] === className) { 
                        results.push(node); 
                        break; 
                    } 
                } 
            } 
        }); 
        return results; 
    } 
    
    

    第六章

    6.5 判断是不是数组

    var is array = function (value) {
        return value &&
        typeof value.splice === 'function' &&
        typeof value.length=== 'number' &&
        typeof value === 'object' &&
        ! (value.propertyIsEnumerable ('length'));
    };
    

    写一个Reduce

    Array. method ('reduce', function(f,value) {
    var i;
    for (i=0;i<this.length; i +=1) {
      value = f(this [i], value);
    }
    return value;
    })

    第七章 正则表达式

    7.1 匹配url的正则

    var parse_url =/^ (?: ([A-Za-z]+) :)? (/{0,3}) ( [0-9.-A-Za-z]+)(?:: (d+))? (?:/([^?#]*))?(?:? ([^#]*))? (?:#(.*))?$/;
    
    var url ="http://www.ora.com: 80/goodparts?q#fragment";
    

    匹配数字的reg

    var parse_number =/^-?d+(?:.d*)? (?:e [+-]?dt)?S/i;
    
    var test= function (num) {
    document.writeln(parse number.test (num) );
    
    };
    
    true test ("1");
    false test ('number');
    true  test('98.6");
    false  test ('132.21.86.100');
    true  test ('123.45E-67');
    false  test ('123.45D-67');
  • 相关阅读:
    LVDS汇总
    smtp模块+Gmail搭建邮件发送功能
    网站建立(杂)
    xampp部署elgg
    转xampp 访问出现New XAMPP security concept
    FPGA参考电源
    android开发环境搭建问题
    cadence仿真前电路板设置(转)
    cadence串扰仿真 (转)
    cadence约束管理器总体设置 (转)
  • 原文地址:https://www.cnblogs.com/ppxyq/p/10576838.html
Copyright © 2020-2023  润新知