📄 treewalkerexample2.htm
字号:
<html>
<head>
<title>TreeWalker Example</title>
<script type="text/javascript">
var walker = null;
function makeList() {
var oDiv = document.getElementById("div1");
walker = document.createTreeWalker(oDiv, NodeFilter.SHOW_ELEMENT, null, false);
var oOutput = document.getElementById("text1");
walker.firstChild(); //go to <p>
walker.nextSibling(); //go to <ul>
oNode = walker.firstChild(); //go to <li>
while (oNode) {
oOutput.value += oNode.tagName + "\n";
oNode = walker.nextSibling();
}
}
</script>
</head>
<body>
<p><strong>Note:</strong> The <code>TreeWalker</code> object has only been implemented in Opera (version 7.6 and higher), Safari (version 1.3 and higher), and Firefox (version 1.0 and higher). It has not been implemented in Internet Explorer (so this example won't work).</p>
<div id="div1">
<p>Hello <b>World!</b></p>
<ul>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ul>
</div>
<textarea rows="10" cols="40" id="text1"></textarea><br />
<input type="button" value="Make List" onclick="makeList()" />
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -