0

This is a simple HTML and JS code, but why scripts tag after body tag, count as childNodes of body!?

I am trying it in FF 35

<!DOCTYPE HTML>
<html>
    <head>
    </head>
    <body id='body'>This is only text node</body>
</html>

<script>
    var b;
</script>
<script>
    var b = document.getElementById('body');
    console.log(b.childNodes.item(3).textContent);
</script>
4

1 回答 1

0

正如其他人指出的那样,脚本标签必须在 HTML 标签内,否则浏览器会尝试为您修复它,从而产生不良后果。

于 2015-03-06T15:48:34.187 回答