zoukankan      html  css  js  c++  java
  • 高性能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;
    }

    正美:

  • 相关阅读:
    C#可视化程序设计第三章(3,4)
    "Can’t be opened because Apple cannot check it for malicious software" 解决方案
    Mac系统.DS_Store文件导致IOError: [Errno 20] Not a directory:解决方案
    读书笔记 《局外人》
    Chrome 67之后无法离线安装插件
    函数和方法的区别
    github|webstorm
    webstorm
    Markdown
    github
  • 原文地址:https://www.cnblogs.com/jikey/p/2084627.html
Copyright © 2011-2022 走看看