|
page8-02.html
http://kuai.xunlei.com/d/OCFQRGUOCALO
教你学会获取网页节点,相当简单,适应于自己编的任何网页中!
<html>
<head>
<title>访问相关节点示例</title>
<script language="javascript" type="text/javascript">
<!--
function fnshowNodeInfo(){
var oHtml = document.documentElement;
var oDoc = oHtml.ownerDocument;
var oHead = oHtml.childNodes[0];
var oBody = oHead.nextSibling;
var oTitle = oHead.firstChild;
var oP1 = oBody.firstChild;
var oP2 = oP1.nextSibling;
var oP3 = oBody.lastChild;
var oA = oP1.firstChild;
var oAText = oA.firstChild;
var aNodes = [oDoc, oHtml, oHead, oTitle, oBody, oP1,oA, oAText];
var ah = "第三段";
var sMsg = "<table align=\"center\" border=\"1\"" +
"cellspacing=\"0\" cellpadding=\"3\" width=\"443\">";
sMsg += "<tr><th>节点名称</th><th>节点值</th><th>节点类型</th></tr>";
for(var i = 0; i < aNodes.length; i++)
{
sMsg += "<tr><td>" + aNodes.nodeName;
sMsg += "</td><td>" + aNodes.nodeValue;
sMsg += "</td><td>" + aNodes.nodeType + "</td></tr>";
}
sMsg += "<table>\n";
oP2.innerHTML = sMsg;
oP3.innerHTML =ah;
}
//-->
</script>
</head> |
|