JavaScript 獲取、設置標籤屬性值

晚上正在漫遊網絡,朋友突然叫幫忙寫個js設置標籤屬性的代碼,驚愕標籤屬性之豐富和我輩瞭解使用之少之後,開始嘗試寫這個功能代碼,參考了兩篇文章:http://lionbule.iteye.com/blog/777538和http://blog.csdn.net/li__000/article/details/6738927,代碼寫出來了,測試了firefox11.0、chrome10.0、opera11.01、IE8,都能良好運行,但據朋友說,搜狗瀏覽器不能運行,這個無語了。。。沒多管,記錄下代碼:
<a href="frame.jsp?bs=index" id="test" class="test1" hidefocus=true>棣栭〉</a>
<a href="sadfas.html" id="abc" hidefocus="true">sss</a>
<a href="sfmlsdfsada.h" >ssssdfsd</a>
<a href="safas.html" >sss</a>
<a href="sdfas.hmtml" >sss</a>
<a href="#" >sss</a>
<a href="#" >sss</a>
<script type="text/javascript">
var s = document.getElementsByTagName("a");
for(var i=0;i<s.length;i++){
s[i].setAttribute("hidefocus","true");
alert(s[i].attributes["hidefocus"].value);
}
</script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章