Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

[·­Òë]High Performance JavaScript(009)

µÚÈýÕ  DOM Scripting  DOM±à³Ì
    DOM scripting is expensive, and it's a common performance bottleneck in rich web applications. This chapter discusses the areas of DOM scripting that can have a negative effect on an application's responsiveness and gives recommendations on how to improve response time. The three categories of problems discussed in the chapter include:
    ¶ÔDOM²Ù×÷´ú¼Û°º¹ó£¬ÔÚ¸»ÍøÒ³Ó¦ÓÃÖÐͨ³£ÊÇÒ»¸öÐÔÄÜÆ¿¾±¡£±¾ÕÂÌÖÂÛ¿ÉÄܶԳÌÐòÏìÓ¦Ôì³É¸ºÃæÓ°ÏìµÄDOM±à³Ì£¬²¢¸ø³öÌá¸ßÏìÓ¦ËٶȵĽ¨Òé¡£±¾ÕÂÌÖÂÛÈýÀàÎÊÌ⣺
• Accessing and modifying DOM elements
·ÃÎʺÍÐÞ¸ÄDOMÔªËØ
• Modifying the styles of DOM elements and causing repaints and reflows
ÐÞ¸ÄDOMÔªËصÄÑùʽ£¬Ôì³ÉÖØ»æºÍÖØÐÂÅÅ°æ
• Handling user interaction through DOM events
ͨ¹ýDOMʼþ´¦ÀíÓû§ÏìÓ¦
    But first—what is DOM and why is it slow?
    µ«Ê×ÏÈ——ʲôÊÇDOM£¿ËûΪʲôÂý£¿
DOM in the Browser World  ä¯ÀÀÆ÷ÊÀ½çÖеÄDOM
    The Document Object Model (DOM) is a language-independent application interface (API) for working with XML and HTML documents. In the browser, you mostly work with HTML documents, although it's not uncommon for web applications to retrieve XML documents and use the DOM APIs to access data from those documents.
    Îĵµ¶ÔÏóÄ£ÐÍ£¨DOM£©ÊÇÒ»¸ö¶ÀÁ¢ÓÚÓïÑԵģ¬Ê¹ÓÃXMLºÍHTMLÎĵµ²Ù×÷µÄÓ¦ÓóÌÐò½Ó¿Ú£¨API£©¡£ÔÚä¯ÀÀÆ÷ÖУ¬Ö÷ÒªÓëHTMLÎĵµ´ò½»µÀ£¬ÔÚÍøÒ³Ó¦ÓÃÖмìË÷XMLÎĵµÒ²ºÜ³£¼û¡£DOM APIsÖ÷ÒªÓÃÓÚ·ÃÎÊÕâЩÎĵµÖеÄÊý¾Ý¡£
    Even though the DOM is a language-independent API, in the browser the interface is implemented in JavaScript. Since most of the work in client-side scripting has to do with the underlying document, DOM is an important part of everyday JavaScript coding.
    ¾¡¹ÜDOMÊÇÓëÓïÑÔÎ޹صÄAPI£¬ÔÚä¯ÀÀÆ÷ÖеĽӿÚÈ´ÊÇÒÔJavaScriptʵÏֵġ£¿Í»§¶Ë´ó¶àÊý½Å±¾³ÌÐòÓëÎĵµ´ò½»µÀ£¬DOM¾Í³ÉΪJavaScript´úÂëÈÕ³£ÐÐΪÖÐÖØÒªµÄ×é³É²¿·Ö¡£
  


Ïà¹ØÎĵµ£º

javascriptЧÂʾ­Ñé̸(Ò»)

±¾ÎÄÖ÷ÒªÊdzöÓÚÓÐÅóÓÑʹÓÃÎÒÔ­À´Ð´µÄautocompleteµÄJS¿Ø¼þ¡£µ±Êý¾ÝÁ¿´óµÄʱºò£¬»á³öÏÖЧÂʼ«ÆäÂýµÄÇé¿ö£¬ÎÒÔÚÕâ¶Îʱ¼ä×ö³öµÄһЩ²âÊÔÒ²¼°Ò»Ð©¾­Ñ飬Óë´ó¼Ò·ÖÏí£¬Èç¹ûÓдíµÄµØ·½£¬»¹ÇëÖ¸³ö¡£
¾­¹ý²âÊÔ£¬ÎÒÃǻᷢÏÖÈçϵÄÇé¿ö»òÕß˵µÄ½áÂÛ£¬Èç¹ûÄúµÄ²âÊÔ½á¹ûÓëÎҵIJ»·û£¬Çë˵Ã÷Ô­Òò£¬ÒÔ±ãÏ໥ѧϰ¡£
1£©µ±Ò»¸ö½Ï´óµÄHTML×Ö· ......

ÓÃJavaScriptÀ´ÊµÏÖһЩ¼òµ¥µÄ¿Ø¼þÑéÖ¤

Ò³ÃæÒ»£º
<html>
 <head>
  <title> ÑéÖ¤ÓëÌá½»Ò» </title>
   <script>
    function focusSelect(ID)   //µ±ÑéÖ¤²»ÄÜͨ¹ýʱ»ñµÃÑéÖ¤¿Ø¼þµÄ½¹µãºÍÄÚÈÝ
 {
        document.getElementById(I ......

JavascriptÃæÏò¶ÔÏó±à³Ì£¨Èý£©£º·Çº¯Êý¶ÔÏóµÄ¼Ì³Ð


×òÌ죬ÎÒ±¾À´´òË㣬°ÑÕâ¸ö»°Ìâ½áÊøÁË¡£
µ«ÊÇ£¬Ð´µ½Ò»°ëµÄʱºò£¬ÎÒͻȻÒâʶµ½£¬JavascriptµÄ¼Ì³ÐÓÐÁ½ÖÖ¡£Ò»ÖÖÊÇ»ùÓÚ"º¯Êý¶ÔÏó"µÄ¼Ì³Ð£¬Ò²¾ÍÊÇÒ»¸öfunctionÈ¥¼Ì³ÐÁíÍâÒ»¸öfunction£¬Õâ¸öÎÒÒѾ­ÔÚ×òÌì½éÉܹýÁË¡£
ÁíÒ»ÖÖÔòÊÇ»ùÓÚ"·Çº¯Êý¶ÔÏó"µÄ¼Ì³Ð£¬²»Éæ¼°function¡£ËüµÄ×ö·¨ÓëÇ°Ò»ÖÖÇé¿öÍêÈ«²»Í¬¡£
Ò»¡¢Ê²Ã´ÊÇ"·Çº¯Êý¶ÔÏ ......

JavaScriptѧϰ±Ê¼Ç£¨Áù£©

1.DOMÊÇÕë¶ÔXMLµÄ»ùÓÚÊ÷µÄAPI¡£Ê¹ÓÃDOM£¬Ö»Ðè½âÎö´úÂëÒ»´ÎÀ´´´½¨Ò»¸öÊ÷µÄÄ£ÐÍ¡£ÔÚÕâ¸ö³õʼ½âÎö¹ý³ÌÖ®ºó£¬XMLÒѾ­Íêȫͨ¹ýDOMÄ£ÐͱíÏÖ³öÀ´£¬Í¬Ê±Ò²²»ÔÙÐèҪԭʼµÄ´úÂë¡£
   NB
£ºDOMÊÇÓïÑÔÎ޹صÄAPI£¬Ëü²¢²»ÓëJava¡¢JavaScript»òÆäËûÓïÑ԰󶨡£ ......

[·­Òë]High Performance JavaScript(006)

Identifier Resolution Performance  ±êʶ·ûʶ±ðÐÔÄÜ
    Identifier resolution isn't free, as in fact no computer operation really is without some sort of performance overhead. The deeper into the execution context's scope chain an identifier exists, the slower it is to access for ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ