JS获取HTML元素属性【转】
生活随笔
收集整理的這篇文章主要介紹了
JS获取HTML元素属性【转】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<script type="text/javascript">function test() {var d1 = document.getElementById('d1');var p1 = document.getElementById('p1');alert(d1.alt); // 僅IE支持
alert(p1.alt); // 僅IE支持
alert(d1.getAttribute('alt')); // IE、FF、谷歌瀏覽器都支持
alert(p1.getAttribute('alt')); // IE、FF、谷歌瀏覽器都支持
}
</script>
<div id="d1" alt='ddd_1_2'>測試一
</div>
<p id="p1" alt='ppp_1_2'>測試二
</p>
<input type="button" value="測試" onclick="test()" /> alt為自定義屬性 原文地址:http://hi.baidu.com/weforhappy/item/26da02cd8ce60b3e44941698
轉載于:https://www.cnblogs.com/Blessing/archive/2012/09/08/2676215.html
總結
以上是生活随笔為你收集整理的JS获取HTML元素属性【转】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hadoop hive安装手记(转)
- 下一篇: 我的WCF之旅(12):使用MSMQ进行