HTML代码:
<ul id="ul">
<li><a href="//www.baidu.com">这是个链接地址,...</a></li>
<li><a href="//www.taobao.com">这是个链接地址,...</a></li>
<li><a href="//www.qq.com">这是个链接地址,...</a></li>
<li><a href="//www.youku.com">这是个链接地址,...</a></li>
<li><a href="//www.360buy.com">这是个链接地址,...</a></li>
</ul>
<input id="faviconBtn" type="button" value="出现吧,为师的完全体!" />
JS代码:
var eleLinks = document.getElementById("ul").getElementsByTagName("a"), lenLink = eleLinks.length;
document.getElementById("faviconBtn").onclick = function() {
if (this.value.indexOf("了") === -1) {
for (var index = 0; index < lenLink; index += 1) {
eleLinks[index].innerHTML = '<img src="//g.etfv.co/'+ eleLinks[index].href +'" align="absmiddle" />' + eleLinks[index].innerHTML;
}
this.value = "哈哈哈,出现了吧!";
} else {
this.value = "哥,别点了,我早不干了!";
}
};