2012年8月16日星期四

【深入xx】二三

【深入xx】二三

深入理解JavaScript系列(23):JavaScript与DOM(上)
http://www.cnblogs.com/TomXu/archive/2012/02/16/2351331.html

<!DOCTYPE html><html lang="zh-CN"><head>    <meta charset="utf-8" />    <title></title></head><body>    <div>        <p>1</p>        <p id="some-id">This is text</p>        <p>2</p>    </div>    <script type="text/javascript">        var theDiv = document.getElementsByTagName('div')[0];        var paragraph = document.getElementById('some-id');        console.log(            paragraph.id,            paragraph.getAttribute('id'),            paragraph.parentNode,            // 以下,空格换行带来不是想要的结果            paragraph.firstChild,            paragraph.childNodes[0],            paragraph.lastChild,            paragraph.nextSibling,            paragraph.previousSibling        );        if (paragraph.nextSibling.nodeType == 3) {            alert('fuck');        }    </script></body></html>

TAG: