Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用标签名称和属性就是这样,所以我可以安全地使用 examplehasAttribute和tagName其他类似方法。
hasAttribute
tagName
(我的问题是一种积极要求 html 元素的方法,而不是排除所有可能性,如字符串、数字、某种其他对象等)
你检查它是否是一个实例HTMLElement
HTMLElement
if (varName instanceof HTMLElement){ // do what you want with the node }