【问题标题】:how to compare a specific attribute of nodelists如何比较节点列表的特定属性
【发布时间】:2023-01-05 21:19:10
【问题描述】:

我想使用该节点 exp 的特定属性比较两个节点列表:outHTML,其他任何内容

const a = new DOMParser().parseFromString(this.cntnt,'text/html').documentElement.querySelector('p'));
const b = new DOMParser().parseFromString(this.txt,'text/html').documentElement.querySelector('p'));

例如,如何将 a 和 b 与他们的 outHTML 进行比较?

【问题讨论】:

  • 至于你的问题,你想要什么结果?你传递什么字符串?应该发生什么?

标签: javascript


【解决方案1】:

NodeList 对象是从文档中提取的节点列表(集合)。

NodeList 对象与 HTMLCollection 对象几乎相同。

某些(较旧的)浏览器为 getElementsByClassName() 等方法返回 NodeList 对象而不是 HTMLCollection。

所有浏览器都为属性 childNodes 返回一个 NodeList 对象。

大多数浏览器为方法 querySelectorAll() 返回一个 NodeList 对象。

【讨论】:

    猜你喜欢
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多