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;
    }

    正美:

  • 相关阅读:
    用Javascript进行简单的Table点击排序.
    asp也来玩三层?
    用在JavaScript的RequestHelper
    一个JavaScript方法的演变
    自己动手,实现jQuery中的ImageCopper.
    notes on relations
    mutex and condition variable
    virtual destructor
    virtual inheritance
    一道概率题
  • 原文地址:https://www.cnblogs.com/jikey/p/2084627.html
Copyright © 2011-2022 走看看