<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns="
http://www.w3.org/1999/xhtml ">
<kepala>
<meta http-equiv="Jenis Konten" content="teks/html; charset=gb2312" />
<title>4.3 DOM访问文档</title>
<gaya tipe="teks/css">
<!--
.mao {
font-family: "草体";
ukuran font: 18px;
gaya font: miring;
warna: #0000FF;
}
.lagu {
font-family: "宋体";
ukuran font: 24px;
gaya font: miring;
warna: #FF00FF;
}
-->
</gaya>
<skrip bahasa="javascript" type="teks/javascript">
//----------------------------------------------
/*var p3 = document.getElementsByTagName('p')[3];//根据 TagName 获取元素
p3.className = 'lagu';*/
//----------------------------------------------
/*var p2 = document.getElementById('p2');//根据 Id 获取元素
p2.className = 'lagu';*/
//----------------------------------------------
/*var p1 = document.getElementsByTagName('p')[0].firstChild;//获取子节点
p1p1.nodeValue = p1.nodeName;//nodeType 中1表示元素结点,3表示文本结点 */
//----------------------------------------------
/*var pTags = document.getElementsByTagName('p');//遍历 p 元素
for(var pTag = 0;pTag < pTags.panjang;pTag ++){
var tag = pTag[pTag].anak pertama;
tagtag.nodeValue = tag.nodeName;
}*/
//----------------------------------------------
/*var bodyTag = document.getElementsByTagName('body')[0];//遍历子节点
tag var = bodyTag.childNodes;
var info = "info: n"
for(var num = 0;num < tag.length ;num ++){//IE 与其它不同的是不会把换行符当作文本节点
var tag = tag[angka];
info +="t" + tag.nodeName + "n";
}
peringatan(info);*/
//----------------------------------------------
/*var aHref = document.getElementById('aHref');//遍历父节点
while(aHref.nodeName != "BODY"){
peringatan(aHref.nodeName);
aHrefaHref = aHref.parentNode;
}
peringatan(aHref.nodeName);*/
//----------------------------------------------
/*var p2 = dokumen.getElementById('p2');
var info = "info:n";
var suhu = p2;
while(temp != null){//前节点的next 点
info += "berikutnya: " + temp.nodeName + "n";
temptemp = temp.nextSibling;
}
suhu = p2;
while(temp != null){//前节点的 kembali 节点
info += "kembali: " + temp.nodeName + "n";
temptemp = temp.previousSibling;
}
peringatan(info);*/
//----------------------------------------------
/*var imgTag = dokumen.getElementsByTagName("img")[0];
//imgTag.src = '';
//alert(imgTag.getAttribute('src') )
imgTag.setAttribute("src","
");//修改元素属性
imgTag.setAttribute("title","126电子邮箱");*/
/*var aHref = document.createElement('a');//创建一个标签节点
aHref.setAttribute('href','http://g.cn');
var textInfo = document.createTextNode('一首歌');//创建一个文本节点
aHref.appendChild(textInfo);//添加子节点
var aOld = document.getElementsByTagName('a')[1];
var bodyTag = dokumen.getElementsByTagName('body')[0];
bodyTag.replaceChild(aHref,aOld);//替换一个节点
//bodyTag.insertBefore(aHref,aOld);//把 aHerf 插入到 aOld 之前
//bodyTag.removeChild(aOld);//移除节点*/
//----------------------------------------------
fungsi menyenangkanOnload(){
}
tampilan fungsi(){
var hTag = dokumen.getElementsByTagName('h1')[0];
hTag.innerHTML="innerHTML,<a href='http://g.cn' >12345,上山打老虎</a>";
}
</skrip>
</kepala>
<tubuh onload="funOnload()">
<p class="mao">显示1</p>
<p class="mao" id="p2">显示2</p>
<p class="mao">
<a href=" http://qqface.knowsky.com/ " id="aHref"> qq表情</a></p>
<p class="mao">显示4</p>
<img src="