• 高性能JS比较nextSibling,ChildNodes,Children速度


    原书中说:IE中nextSibling比childNodes表现优异。在IE6中,nextSibling快16倍,IE7中是105倍。

    经测试后发现:IE7下:nextSibling要快一些,childNodes与childnren速度相当。IE6下:nextSibling与childNodes差别相当大,children稍快。FF下还是nextSibling快一点。

    function testNextSibling(){
        
    var el = $('mydiv'),
            ch 
    = el.firstChild,
            name 
    = '';
        
    do {
            name 
    = ch.nodeName;
        } 
    while (ch = ch.nextSibling);
        
    return name;
    }
    function testChildNodes(){
        
    var el = $('mydiv'),
            ch 
    = el.childNodes,
            len 
    = ch.length,
            name 
    = '';
        
    for(var count=0; count<len; count++){
            name 
    = ch[count].nodeName;
        }
        
    return name;
    }
    function testChildren(){
        
    var el = $('mydiv'),
            ch 
    = el.children,
            len 
    = ch.length,
            name 
    = '';
        
    for(var count=0; count<len; count++){
            name 
    = ch[count].nodeName;
        }
        
    return name;
    }

    正美:

  • 相关阅读:
    DLL文件的原理
    OD使用教程7(上) 调试篇07|解密系列
    复制独立数组的方法
    [转载 js] js正则表达式
    中国雅虎ued成员
    复制独立数组的方法
    [转载 js] js正则表达式
    以前做的flash相册
    编程的幽默
    我最早的全flash站
  • 原文地址:https://www.cnblogs.com/jikey/p/2084627.html
Copyright © 2020-2023  润新知