<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>? <head>??? <title>Node節點對象練習2</title>?? ???? <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">??? <meta http-equiv="description" content="this is my page">??? <meta http-equiv="content-type" content="text/html; charset=UTF-8">? </head>? <body>?? ?? ??? ??? <ul>?? ?? ??? ? <li id="bj" value="beijing">?? ?? ??? ? 北京?? ??? ??? ?<p>海淀?? ??? ??? ?</p>?? ??? ??? ?奧運?? ?? ??? ? </li>?? ??? ? <li id="sh" value="shanghai">上海</li>?? ??? </ul>?? ? ?? </body>? ? <script type="text/javascript">? ?? ???? //同時打印文本值? 北京 海淀? 奧運 ?? ?? ?var v=document.getElementById('bj');?? ?var a=document.getElementsByTagName('p');?? ?alert(v.childNodes[0].nodeValue+a[0].childNodes[0].nodeValue+v.childNodes[2].nodeValue);//獲得 body 元素的子節點集合:? </script>? </html>為什么第二個[0]要加在a后面不加在childNodes后面,還有為什么要獲取子元素?子元素不是子標簽的元素嗎這里沒有
javascriptdom問題
慕粉3884565
2016-10-31 13:22:19