MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

Attr.localName

这篇翻译不完整。请帮忙从英语翻译这篇文章

Attr.localName为只读属性,返回the local part of the qualified name of an element。

在DOM4之前此API被定义在Node接口里。

语法

name = attribute.localName

返回值

A DOMString representing the local part of the attribute's qualified name.

例子

下列例子将在alert中显示"id"。

HTML部分

<button id="example">Click me</button>

JavaScript部分

const element = document.querySelector("#example");
element.addEventListener("click", function() {
  const attribute = element.attributes[0];
  alert(attribute.localName);
});

注意

The local name of an attribute is the part of the attribute's qualified name that comes after the colon. Qualified names are typically used in XML as part of the namespace(s) of the particular XML documents.

注意: 在Gecko 1.9.2或更早的版本,这个属性返回大写的the local name for HTML attributes in HTML DOMs (as opposed to XHTML attributes in XML DOMs). In later versions, in compliance with HTML5, the property returns in the case of the internal DOM storage, which is lower case for both HTML attributes in HTML DOMs and XHTML attributes in XML DOMs.

规格

规格 状态 注释
DOM4
Attr.localName
Recommendation Initial definition

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 46.0[1] 48.0 (48.0)[1] ? (Yes) ?
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? 48.0 (48.0)[1] ? ? ?

[1] This API was previously available on the Node API.

参考

文档标签和贡献者

 此页面的贡献者: lixuanh
 最后编辑者: lixuanh,