[翻译]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的history.go(-1)
echo '<script language="javascript">{alert("留言不能为空!");history.go(-1);}</script>';}
echo '<script language="javascript">{alert("留言不能为空!");return true;}</script>';}
这是不刷新页面的方式 ......
// 调用页面的刷新方法
IHTMLWindow2* pWindow;
IHTMLDocument2* pDocument;
HRESULT hr = GetDHtmlDocument(&pDocument);
hr = pDocument->get_pa ......
1.DOM是针对XML的基于树的API。使用DOM,只需解析代码一次来创建一个树的模型。在这个初始解析过程之后,XML已经完全通过DOM模型表现出来,同时也不再需要原始的代码。
NB
:DOM是语言无关的API,它并不与Java、JavaScript或其他语言绑定。 ......
功能:
重新加载文档。
语法:
location.reload(force)
参数:
force:可选参数,是一个布尔值。
如果省略参数,或者参数是false,它就会用HTTP头If-Modified-Since来检测服务器上的文档是否已改变。如果文档已改
变,reload()会再次下载该文档。如果文档未改变,则该方法将从缓存中 ......
Nested Members 嵌套成员
Since object members may contain other members, it's not uncommon to see patterns such as window.location.href in JavaScript code. These nested members cause the JavaScript engine to go through the object member resolution process each time a dot is ......