此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Attr.prefix

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

Attr.prefix 为只读属性,返回指定标签属性的名字空间前缀,如果没有前缀则返回 null

备注: 在 DOM4 之前此 API 被定义在 Node 接口中。

示例

下例在控制台中输出“x”。

xml
<div x:id="example" onclick="console.log(this.attributes[0].prefix)"/>

注意

该属性仅在使用有名字空间解析功能的解析器时有效,例如一个 MIME 类型为 XML 的文档。在 HTML 文档中无效。

规范

Specification
DOM
# dom-attr-prefix

浏览器兼容性

参考