在我學習核心JavaScript的嘗試中,我現在正在學習EventListeners。事件監聽器的問題
我的問題是,在EventListener下面的代碼沒有在IE中被觸發(在Firefox和Chrome中工作得很好)。
有人能告訴我我做錯了什麼嗎?
我的代碼是:
<p>The first captain of the USS Enterprise NCC-1701 was
<a id="wikipedia" href="http://en.wikipedia.org">Christopher Pike</a>.
</p>
<script type="application/javascript">
var link = document.getElementById("wikipedia");
// for firefox and other browsers
if (typeof link.addEventListener != "undefined")
{
link.addEventListener("click", clickListener, false);
}
// IE only
else if (typeof link.attachEvent != "undefined")
{
link.attachEvent("onclick", clickListener);
}
function clickListener()
{
var link = document.getElementById("wikipedia");
link.setAttribute("href", "www.mysite.com/");
open("http://www.mysite.com");
return false;
}
</script>
我根據你的建議修正了它,它仍然沒有在IE – Dmitris 2009-07-26 08:43:16
下工作發現了真正的問題,改變了type屬性。 – 2009-07-26 08:49:26