單擊連結後顏色變化效果,js,css代碼__js

來源:互聯網
上載者:User

僅使當前點擊的超連結為紅顏色,將以下指令碼放到頁面尾部即可。

<Style type="text/css">
.a1 :visited{text-decoration: none; color:#ff0000 }
</Style>

<script type="text/javascript">
var lab1 = document.getElementsByTagName("a");//尋找標籤<a>
for (var i = 0; i < lab1.length; i++)
{
lab1[i].onclick =function(){ clickon (this) };
//大量新增事件
}


function clickon (obj)
{
   var lab2 = document.getElementsByTagName("a");
   for (var i = 0; i < lab2.length; i++)
   {
    lab2[i].className="";//清除所有<a>的class內容
   }
    obj.className="a1 ";//添加當前<a>的class內容
}
</script>

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.