HTML是這樣的:通過ID更改標籤的背景顏色
<div class="header">
<ul>
<li>
<a class="abc" id="abc" href="www.testing.com">testing</a>
</li>
</ul>
</div>
我的JavaScript是這樣的:
<script language="javascript" type="text/javascript">
var links = document.getElementById("abc");
var a = links.getElementsByTagName("a");
var thisLocationHref = window.location.href;
for(var i=0;i<a.length;i++)
{
var tempLink = a[i];
if(thisLocationHref === tempLink.href)
{
tempLink.style.backgroundColor="red";
}
else
{
tempLink.style.backgroundColor="blue";
}
}
,因爲它涉及另一頁,我不能在標籤刪除ID。 我知道代碼有問題,但無法弄清楚在哪裏。 歡迎任何幫助! 謝謝!
我想這只是你的例子中的一個錯字,但在a-tag中沒有href – RST 2013-05-09 00:09:54
哦,是的。我忘了添加href鏈接...我已經添加了。謝謝。 – Pluto 2013-05-09 00:12:42