ITeye博客

getAttribute取得元素属性值

小丑鱼0703 · 2015-03-04 14:48 · js-Dom · Web前端 · Markdown

getAttribute(strAttributeName, lFlags) 取得属性值。

<div id="div1" class="divname" title="div"></div> 
var el = document.getElementById("div1");  
alert(el.getAttribute("id"));//div1

https://msdn.microsoft.com/zh-cn/subscriptions/ms536429.aspx中介绍了lFlags参数的意义: 0 Default. Performs a property search that is not case-sensitive, and returns an interpolated value if the property is found.

1 strAttributeName大小写完全匹配 Performs a case-sensitive property search. To find a match, the uppercase and lowercase letters in strAttributeName must exactly match those in the attribute name.

2 Returns attribute value as a String. This flag does not work for event properties.

4 Returns attribute value as a fully expanded URL. Only works for URL attributes.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。