js学习笔记(-)
1.改变文档
document 在权威指南的chapter15;
loaction 属性 for example :location = "shake01.htm";
同样也可以使用location.href;
对于利用href:来操作js,
依我的理解可能只是重写html文档,很难,
不知有什么好的见解.
对于document 的其他属性,我以后在学习。
标签数的记数,
function countTags(n) { // n is a Node
var numtags = 0; // Initialize the tag counter
if (n.nodeType == 1 /*Node.ELEMENT_NODE*/) // Check if n is an Element
numtags++; // Increment the counter if so
var children = n.childNodes; // Now get all children of n
for(var i=0; i < children.length; i++) { // Loop through the children
numtags += countTags(children[i]); // Recurse on each one
}
return numtags; // Return the total
}
很喜欢这段函数,真简洁,是从js权威指南上搞得。^_^
nodeType constant nodeType value
Element Node.ELEMENT_NODE 1
Text Node.TEXT_NODE 3
Document Node.DOCUMENT_NODE 9
Comment Node.COMMENT_NODE 8
DocumentFragment Node.DOCUMENT_FRAGMENT_NODE 11
Attr Node.ATTRIBUTE_NODE 2
运用递归算法来逐个标签来是计算,运用了childNodes,
nodetuype 来check 本身是否是一元素,
就写这么多了,晚上继续写。