?? domtest1.html
字號:
<html>
<head>
<title>DOM Page</title>
</head>
<script>
function showElement(){
var element=document.getElementById("h1");//h1是一個<h1>標簽
alert(element.nodeType);//nodeType=1
alert(element);
}
function showText(){
var element=document.getElementById("h1");
var text=element.childNodes[0];//取得h1中的文字
alert(text.nodeType);//nodeType=3
alert(text);
alert(text.data);
}
function showDocument(){
alert(document.nodeType);//document的nodeType=9
alert(document);
}
function showAttr(){
var btn1=document.getElementById("btn1");//btn1是一個按鈕,它有很多屬性
var attrs=btn1.attributes;//取得這個按鈕的屬性
for(var i=0;i<attrs.length;i++){
var attr=attrs[i];
alert(attr.nodeType);//nodeType=2
alert(attr);
alert(attr.name+"="+attr.value);
}
}
</script>
<body>
<h1 id="h1">An HTML Document</h1>
<p id="p1">This is a <i>W3C HTML DOM</i> document.</p>
<input id="btn1" type="button" value="Element_Node" onclick="javascript:showElement();"><br>
<input type="button" value="Text_Node" onclick="javascript:showText();"><br>
<input type="button" value="Document_Node" onclick="javascript:showDocument();"><br>
<input type="button" value="Attr_Node" onclick="javascript:showAttr();"><br>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -