2011-03-09 85 views
0

我在同一個網頁上有類似的代碼,谷歌瀏覽器加載它就好了。但是這個特殊的功能似乎只適用於某些瀏覽器。我自己找不到任何錯誤。也許我可以用不同的方式寫出這個陳述?爲什麼這個Javascript代碼不能在谷歌瀏覽器中工作

<script type="text/JavaScript"> 
<!-- 
function changeWebsite() { 
var currentTime = new Date().getHours();  

if (7 <= currentTime&&currentTime < 17) { 
     document.write(' <img src="http://itsnotch.com/tumblr/images/websitelist_tumblr_VC01.png" width="200" height="45" alt=""> '); 

      document.write(' <a href="http://www.itsnotch.com" <img src="http://itsnotch.com/tumblr/images/websitelist_tumblr_VC02.png" width="200" height="75" border="0" alt="ItsNotch.com"></a> '); 

     document.write(' <a href="http://www.notchtheguru.com" <img src="http://itsnotch.com/tumblr/images/NotchTheGuru.comVC.png" width="200" height="119" border="0" alt="Tumblr"></a>'); 


      document.write('<a href="http://www.bignotch.com" <img src="http://itsnotch.com/tumblr/images/websitelist_tumblr_VC04.png" width="200" height="161" border="0" alt="NotchTheGuru.com"></a>'); 
     } 

     else { 
     document.write(' <img src="http://itsnotch.com/tumblr/images/websitelist_tumblr_01.png" width="200" height="45" alt=""> '); 

      document.write(' <a href="http://www.itsnotch.com" <img src="http://itsnotch.com/tumblr/images/websitelist_tumblr_02.png" width="200" height="75" border="0" alt="ItsNotch.com"></a> '); 

     document.write(' <a href="http://www.notchtheguru.com" <img src="http://itsnotch.com/tumblr/images/NotchTheGuru.com.png" width="200" height="119" border="0" alt="Tumblr"></a>'); 


      document.write('<a href="http://www.bignotch.com" <img src="http://itsnotch.com/tumblr/images/websitelist_tumblr_04.png" width="200" height="161" border="0" alt="NotchTheGuru.com"></a>'); 
     } 

     } 


changeWebsite(); 
--> 
</script> 

回答

5

您錯過了所有錨定標記上的右括號。

5

代碼工作正常,但您沒有關閉開啓定位標記。

<a href="http://www.notchtheguru.com" <img 

應該

<a href="http://www.notchtheguru.com"> <img 
1

你有幾乎所有的document.write()線的一個大問題是,它們含有破碎的HTML代碼。

它們都有同樣的問題,就是<a>標記在<img>標記開始之前未正確關閉 - 即您錯過了>

HTML中的這種語法錯誤極有可能導致跨瀏覽器呈現問題。

相關問題