Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js-dom笔记中的nodetype问题 #17

Open
Cn-0kr opened this issue Jul 6, 2024 · 0 comments
Open

js-dom笔记中的nodetype问题 #17

Cn-0kr opened this issue Jul 6, 2024 · 0 comments

Comments

@Cn-0kr
Copy link

Cn-0kr commented Jul 6, 2024

佬好!
在js的dom笔记中我有一个疑问:

<body>
  <div id="box">
    <p>我是段落A</p>
    <p id="para">我是段落B</p>
    <p>我是段落C</p>
  </div>

  <script>
    var box = document.getElementById('box');
    var para = document.getElementById('para');
    console.log(box.firstChild.nodeType);

这里nodetype的输出是3,但是我并不明白是为什么。于是我去询问了下gpt,得到了答案:
根据W3C标准,nodeType 的值定义如下:

1 - Element 节点
2 - Attribute 节点(已废弃)
3 - Text 节点
4 - CDATASection 节点(仅在 XML 中有效)
5 - EntityReference 节点(已废弃)
6 - Entity 节点(已废弃)
7 - ProcessingInstruction 节点
8 - Comment 节点
9 - Document 节点
10 - DocumentType 节点
11 - DocumentFragment 节点
12 - Notation 节点(已废弃)
第一个节点是多出的空行text,因此返回3.我觉得这里的笔记好像没有讲到nodetype对应的值的问题,因此拉了一个issue,希望您能看到!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant