JS获取HTML元素属性【转】

it2022-05-08  8

<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


最新回复(0)