[翻译]High Performance JavaScript(010)
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().
使用DOM方法更新页面内容的另一个途径是克隆已有DOM元素,而不是创建新的——即使用element.cloneNode()(element是一个已存在的节点)代替document.createElement();
Cloning nodes is more efficient in most browsers, but not by a big margin. Regenerating the table from the previous example by creating the repeating elements only once and then copying them results in slightly faster execution times:
在大多数浏览器上,克隆节点更有效率,但提高不太多。用克隆节点的办法重新生成前面例子中的表,单元只创建一次,然后重复执行复制操作,这样做只是稍微快了一点:
• 2% in IE8, but no change in IE6 and IE7
在IE8中快2%,但在IE6和IE7中无变化
• Up to 5.5% in Firefox 3.5 and Safari 4
在Firefox 3.5和Safari 4中快了5.5%
• 6% in Opera (but no savings in Opera 10)
在Opera中快了6%(但是在Opera 10中无变化)
• 10% in Chrome 2 and 3% in Chrome 3
在Chrome 2中快了10%,在Chrome 3中快了3%
As an illustration, here's a partial code listing for generating the table using element.cloneNode():
一个示例,这里是使用element.cloneNode()创建表的部分代码:
function tableClonedDOM() {
var i, table, thead, tbody, tr, th, td, a, ul, li,
oth = document.createElement('th'),
otd = document.createElement('td'),
otr = document.createElement('tr'),
oa = document.createElement('a'),
oli = document.createElement('li'),
oul = document.createElement('ul');
tbody = document.createElement('tbody');
for (i = 1; i <= 1000; i++) {
tr = otr.cloneNode(false);
td = otd.cloneNode(false);
&nb
相关文档:
在Web开发中,会遇到从一页(父页)导向另一页(子页),并且要求“返回”父页的情况,在这里如果用ASP.NET提供的 Response.Redirect()方法,往往不会达到理想的效果,例如:返回后,重新加载了页面,无法保存导向子页前的状态,等等,在这里我就介绍 一下如何使用JavaScript中history.go()函数来实现返回 ......
1. document.formName.item("itemName") 问题
说明:IE下,可以使用document.formName.item("itemName")或document.formName.elements["elementName"];
Firefox下,只能使用document.formName.elements["elementName"].
解决方法:统一使用document.formName.elements["elementName"].
2.集合类对象问题
说明:IE下,可 ......
J
SON (JavaScript Object Notation)一种简单的数据格式,比xml更轻巧。 JSON 是 JavaScript 原生格式,这意味着在 JavaScript 中处理 JSON 数据不需要任何特殊的 API 或工具包。
JSON的规则很简单: 对象是一个无序的“‘名称/值’对”集合。一个对象以“{”(左括号)开始,“ ......
**
* 我在网上看到过很多BASE64的JavaScript算法,都觉得不满意,于是自己写了一个,在这里分享一下。
* 我的代码在质量的效率都较高,没有一些冗余的操作。总体来讲我觉得非常不错。
* 如果大家有什么不懂的地方可以问我。
*/
var BASE64={
/**
* 此变量为编码的 ......
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 ......