gpt4 book ai didi

javascript - 在 JS 中,我应该向 hasAttributeNS() 和 getAttributeNS() 的命名空间参数提供什么值来指示 "no namespace"?

转载 作者:行者123 更新时间:2023-11-30 09:32:08 25 4
gpt4 key购买 nike

我很难找到 hasAttributeNS()getAttributeNS() 的规范,它告诉我在“无 namespace ”的情况下为第一个参数提供什么“属性。根据经验,似乎 ""不起作用,而 null 起作用,但这只是一种实现,我不知道我是否可以安全地依赖它。

指向规范的指针会很有用。

最佳答案

这是来自 the specification :

DOM Level 2 doesn't perform any URI normalization or canonicalization. The URIs given to the DOM are assumed to be valid (e.g., characters such as whitespaces are properly escaped), and no lexical checking is performed. Absolute URI references are treated as strings and compared literally. How relative namespace URI references are treated is undefined. To ensure interoperability only absolute namespace URI references (i.e., URI references beginning with a scheme name and a colon) should be used. Note that because the DOM does no lexical checking, the empty string will be treated as a real namespace URI in DOM Level 2 methods. Applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.

hasAttributeNs :

hasAttributeNS introduced in DOM Level 2  
Returns true when an attribute with a given local name and namespace URI is specified on this element or has a default value, false otherwise. HTML-only
DOM implementations do not need to implement this method.

Parameters
namespaceURI of type DOMString
The namespace URI of the attribute to look for.
localName of type DOMString
The local name of the attribute to look for.

关于javascript - 在 JS 中,我应该向 hasAttributeNS() 和 getAttributeNS() 的命名空间参数提供什么值来指示 "no namespace"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45634537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com