--- title: Element.localName slug: Web/API/Element/localName translation_of: Web/API/Element/localName ---
Element.localName 只读属性,返回本地名称的.
在DOM4之前这个API定义在{{domxref("Node")}}接口。
name = element.localName
{{domxref("DOMString")}} 返回元素限定名的本地部分。
(必须配合XML文档类型, 如 text/xml 或 application/xhtml+xml.)
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:svg="http://www.w3.org/2000/svg">
<head>
<script type="application/javascript"><![CDATA[
function test() {
var text = document.getElementById('text');
var circle = document.getElementById('circle');
text.value = "<svg:circle> has:\n" +
"localName = '" + circle.localName + "'\n" +
"namespaceURI = '" + circle.namespaceURI + "'";
}
]]></script>
</head>
<body onload="test()">
<svg:svg version="1.1"
width="100px" height="100px"
viewBox="0 0 100 100">
<svg:circle cx="50" cy="50" r="30" style="fill:#aaa" id="circle"/>
</svg:svg>
<textarea id="text" rows="4" cols="55"/>
</body>
</html>
节点的本地名称是节点限定名的一部分出现在冒号之后. 限定名通常当作特定XML文档命名空间的一部分.例如在限定名 ecomm:partners中 partners是本地名,ecomm是前缀。
<ecomm:business id="soda_shop" type="brick_n_mortar" xmlns:ecomm="http://example.com/ecomm">
<ecomm:partners>
<ecomm:partner id="1001">Tony's Syrup Warehouse
</ecomm:partner>
</ecomm:partner>
</ecomm:business>
提示: 在 {{Gecko("1.9.2")}} 之前, 此属性返回HTML DOM的HTML元素本地名称的大写版本 (而不是XML DOM的HTML元素). 在最后一个版本, 符合HTML5规范下, 当HTML DOM的HTML或XML DOMs的XHTML的小写元素时此属性返回内部DOM storage。{{domxref("element.tagName","tagName")}} 属性仍然返回HTML DOM的HTML元素本地名称的大写版本.
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('DOM4', '#interface-element', 'Element.localName')}} | {{Spec2('DOM4')}} | Initial definition |