通過 HTML DOM,您能夠使用節(jié)點(diǎn)關(guān)系在節(jié)點(diǎn)樹中導(dǎo)航。
HTML DOM 導(dǎo)航 語法
getElementsByTagName() 方法返回節(jié)點(diǎn)列表。節(jié)點(diǎn)列表是一個(gè)節(jié)點(diǎn)數(shù)組。
HTML DOM 導(dǎo)航 示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p>Hello World!</p> <p>DOM 是非常有用的!</p> <p>這個(gè)實(shí)例演示了 <b>length</b> 屬性。</p> <script> x=document.getElementsByTagName("p"); for (i=0;i<x.length;i++) { document.write(x[i].innerHTML); document.write("<br>"); } </script> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例