Attr.localName read-only property returns the local part of the qualified name of an attribute.

In previous DOM specifications this API was defined within the 节点 接口。

句法

name = attribute.localName
					

返回值

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

范例

The following example shows "id" in an alert dialog.

HTML 内容

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

JavaScript Content

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 and earlier, the property returns the upper-cased version of 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.

规范

规范 状态 注释
DOM
The definition of 'Attr.localName' in that specification.
实时标准 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
localName Chrome 46
46
This API was previously available on the 节点 API。
Edge ≤18 Firefox 48
48
This API was previously available on the 节点 API。
IE No Opera 33
33
This API was previously available on the 节点 API。
Safari 1.3 WebView Android 46
46
This API was previously available on the 节点 API。
Chrome Android 46
46
This API was previously available on the 节点 API。
Firefox Android 48
48
This API was previously available on the 节点 API。
Opera Android 33
33
This API was previously available on the 节点 API。
Safari iOS 1 Samsung Internet Android 5.0
5.0
This API was previously available on the 节点 API。

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: