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 July 2015.

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

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
prefix

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参考