zoukankan      html  css  js  c++  java
  • 读Javascript高性能编程重点笔记


    //
    高效简洁 //低消能 children            //childNodes childElementCount //childNodes.length firstElementChild //firstChild lastEelmentChild //lastChild nextElementSibling //nextSibling previousElementSibling //previousSibling

     

    选择器的高效应用

    <div id="footer_bottom">
    <a href="/AboutUS.aspx">关于博客园</a><a href="/ContactUs.aspx">联系我们</a><a href="/about/ad.aspx">广告服务</a><a href="/about/job.aspx">人才服务</a><a href="http://www.miibeian.gov.cn">沪ICP备09004260号</a>&copy;2004-2012 <a href="http://www.cnblogs.com/">博客园</a>
    </div>
    var aArr1= document.querySelectorAll("#footer_bottom a");//简洁高效
    var aArr2 = docuement.getElementById("footer_bottom").getElementsByTagName("a");//繁杂低效
    
    //return  
    <a href="/AboutUS.aspx">关于博客园</a>,
    <a href="/ContactUs.aspx">联系我们</a>,
    <a href="/about/ad.aspx">广告服务</a>,
    <a href="/about/job.aspx">人才服务</a>,
    <a href="http://www.miibeian.gov.cn">沪ICP备09004260号</a>,
    <a href="http://www.cnblogs.com/">博客园</a>
    
    //选择第一个子节点
    var a = document.querySelector("#footer_bottom a");
    //return <a href="/AboutUS.aspx">关于博客园</a>
    
    //选择多个节点
    var divs = document.querySelectorAll("div.footer,div.main,div.header");

    注意:大部分浏览器都支持上述属性,IE6,7,8仅支持children属性

    减少DOM的重新渲染与排版(三种方式)

    1.先将要处理的元素隐藏,然后对其处理,最后显示

    2.创建文件片段的方式(推荐) document.createDocumentFragment();

    3.对要处理的元素克隆一个副本,然后对副本操作,最后将副本替换原本

     

     

    你对人生迷茫吗? 那就背起行囊,起步远行吧
  • 相关阅读:
    JAVA程序员面试32问
    在做物流的库存管理系统里,需要注意。。。。。
    在写自动更新程序中出现的问题
    数据库设计中的五个范式
    cPickle / pickle
    python总结1
    python总结2
    汉明距离(Hamming distance)
    python中pickle的用法
    NET面试题
  • 原文地址:https://www.cnblogs.com/daxian2012/p/2663767.html
Copyright © 2011-2022 走看看