现在的位置: 首页 > 综合 > 正文

When innerHTML isn’t Fast Enough[ZT]

2013年03月31日 ⁄ 综合 ⁄ 共 635字 ⁄ 字号 评论关闭
http://blog.stevenlevithan.com/archives/faster-than-innerhtml

 1function replaceHtml(el, html) {   
 2    var oldEl = typeof el === "string" ? document.getElementById(el) : el;   
 3    /*@cc_on // Pure innerHTML is slightly faster in IE  
 4        oldEl.innerHTML = html;  
 5        return oldEl;  
 6    @*/
  
 7    var newEl = oldEl.cloneNode(false);   
 8    newEl.innerHTML = html;   
 9    oldEl.parentNode.replaceChild(newEl, oldEl);   
10    /* Since we just removed the old element from the DOM, return a reference  
11    to the new element, which can be used to restore variable references. */
  
12    return newEl;   
13}
;  
14

抱歉!评论已关闭.