[·Òë]High Performance JavaScript(011)
Repaints and Reflows ÖØ»æºÍÖØÅÅ°æ
Once the browser has downloaded all the components of a page—HTML markup, JavaScript, CSS, images—it parses through the files and creates two internal data structures:
µ±ä¯ÀÀÆ÷ÏÂÔØÍêËùÓÐÒ³ÃæHTML±ê¼Ç£¬JavaScript£¬CSS£¬Í¼Æ¬Ö®ºó£¬Ëü½âÎöÎļþ²¢´´½¨Á½¸öÄÚ²¿Êý¾Ý½á¹¹£º
A DOM tree
A representation of the page structure
Ò»¿ÃDOMÊ÷
±íʾҳÃæ½á¹¹
A render tree
A representation of how the DOM nodes will be displayed
Ò»¿ÃäÖȾÊ÷
±íʾDOM½ÚµãÈçºÎÏÔʾ
The render tree has at least one node for every node of the DOM tree that needs to be displayed (hidden DOM elements don't have a corresponding node in the render tree). Nodes in the render tree are called frames or boxes in accordance with the CSS model that treats page elements as boxes with padding, margins, borders, and position. Once the DOM and the render trees are constructed, the browser can display ("paint") the elements on the page.
äÖȾÊ÷ÖÐΪÿ¸öÐèÒªÏÔʾµÄDOMÊ÷½Úµã´æ·ÅÖÁÉÙÒ»¸ö½Úµã£¨Òþ²ØDOMÔªËØÔÚäÖȾÊ÷ÖÐûÓжÔÓ¦½Úµã£©¡£äÖȾÊ÷ÉϵĽڵã³ÆΪ“¿ò”»òÕß“ºÐ”£¬·ûºÏCSSÄ£Ð͵Ķ¨Ò壬½«Ò³ÃæÔªËØ¿´×÷Ò»¸ö¾ßÓÐÌî³ä¡¢±ß¾à¡¢±ß¿òºÍλÖõĺС£Ò»µ©DOMÊ÷ºÍäÖȾÊ÷¹¹ÔìÍê±Ï£¬ä¯ÀÀÆ÷¾Í¿ÉÒÔÏÔʾ£¨»æÖÆ£©Ò³ÃæÉϵÄÔªËØÁË¡£
When a DOM change affects the geometry of an element (width and height)—such as a change in the thickness of the border or adding more text to a paragraph, resulting in an additional line—the browser needs to recalculate the geometry of the element as well as the geometry and position of other elements that could have been affected by the change. The browser invalidates the part of the render tree that was affected by the change and reconstructs the render tree. This process is known as a reflow. Once the reflow is complete, the browser redraws the affected parts of the screen in a
Ïà¹ØÎĵµ£º
µÚÈýÕ 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 o ......
Cloning Nodes ½Úµã¿Ë¡
Another way of updating page contents using DOM methods is to clone existing DOM elements instead of creating new ones—in other words, using element.cloneNode() (where element is an existing node) instead of document.createElement().
&nbs ......
function db()
{
//»î¶¯±àºÅ
var activeid = Request.Form("activeid");
//̞
var username = Request.Form("username");
//ÊÖ»úºÅÂë
var mobile = Request.Form("mobile");
var conn= Server.CreateObject("ADODB.connection");
var rs= Serve ......
£¼script language="javaScript"£¾
function closeWindow()
{
¡¡window.opener = null;
¡¡window.open(' ', '_self', ' ');
¡¡window.close();
}
£¼/script£¾
£¼input type='button' value='¹Ø±Õ´°¿Ú' onClick="closeWindow()"£¾
»ò
£¼input type="button" value="¹ ......