--- title: Attr.prefix slug: Web/API/Attr/prefix translation_of: Web/API/Attr/prefix --- <div>{{APIRef("DOM")}}</div> <p><code><strong>Attr.prefix</strong></code> 为只读属性,返回指定标签属性的名字空间前缀,如果没有前缀则返回 <code>null</code>。</p> <div class="note"> <p>在 DOM4 之前此 API 被定义在 {{domxref("Node")}} 接口中。</p> </div> <h2 id="语法">语法</h2> <pre class="syntaxbox notranslate"><var>string</var> = <var>attribute</var>.prefix </pre> <h2 id="示例">示例</h2> <p>下例在控制台中输出“x”。</p> <pre class="brush:xml notranslate"><div x:id="example" onclick="console.log(this.attributes[0].prefix)"/> </pre> <h2 id="注意">注意</h2> <p>该属性仅在使用有名字空间解析功能的解析器时有效,例如一个MIME类型为XML的文档。在HTML文档中无效。</p> <h2 id="规范">规范</h2> <table class="standard-table"> <thead> <tr> <th scope="col">规范</th> <th scope="col">状态</th> <th scope="col">备注</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('DOM WHATWG', '#dom-attr-prefix', 'Attr: prefix')}}</td> <td>{{Spec2('DOM WHATWG')}}</td> <td></td> </tr> <tr> <td>{{SpecName("DOM4", "#dom-attr-prefix", "Attr.prefix")}}</td> <td>{{Spec2("DOM4")}}</td> <td></td> </tr> </tbody> </table> <h2 id="浏览器兼容性">浏览器兼容性</h2> <p>{{Compat("api.Attr.prefix")}}</p> <h2 id="参考">参考</h2> <ul> <li>{{domxref("Attr.namespaceURI")}}</li> <li>{{domxref("Attr.localName")}}</li> <li>{{domxref("Element.prefix")}}</li> <li>{{domxref("Node.prefix")}}</li> </ul>