2016-11-22 86 views
0

但是,我想通過函數爲圖像調用我的鼠標上的java腳本函數;調試器說「功能未定義」。我不明白爲什麼我得到這個錯誤。 Java腳本和標籤看起來是正確的,它看起來像我使用正確的語法來調用該函數。在HTML中無法識別的Javascript函數

<!DOCTYPE HTML> 
 
     <html> 
 
     <head> 
 
     <meta charset="utf-8"> 
 
     <title>Chapter11-1</title> 
 
     <script type="text/javascipt"> 
 
     
 
     function overButton(img) { 
 
     \t buttonImg="chapter11-1"+img+"_over.gif" 
 
     \t document.getElementById(img).src=buttonImg 
 
     \t } 
 
     
 
     \t function downButton(img) { 
 
     \t buttonImg="chapter11-1"+img+"_down.gif" 
 
     \t document.getElementById(img).src=buttonImg 
 
     \t } 
 
     
 
     \t function upButton(img) { 
 
     \t buttonImg="chapter11-1"+img+"_up.gif" 
 
     \t document.getElementById(img).src=buttonImg 
 
     \t } 
 
     </script> 
 
     </head> 
 
     <body> 
 
     <div id="banner_logo"><img src="chapter11-1banner.jpg" width="745" height="150" alt="banner" id="banner" /></div> 
 
     <table class="centerItems"> 
 
     \t <tr> 
 
     \t <td> 
 
     \t <a href="#"> 
 
     \t <img src="chapter11-1home_up.gif" id="home" alt="home" onMouseOver="overButton('home')" onMouseDown="downButton('home')" onMouseOut="upButton('home')" onMouseUp="upButton('home')" /></a> 
 
     \t </td> 
 
     </body> 
 
     </html>

+0

這是一個typo.It要註釋。 – jan86

+0

您的HTML無效,這是主要問題,您已經打開TR而不關閉它,未關閉的桌子等。 – adeneo

+0

有一刻我會添加整個標記。 – jan86

回答

0

它不工作,因爲你拼寫爲 「JavaScript的」 錯誤。
更改此

<script type="text/javascipt"> 

<script type="text/javascript"> 

或只是

<script> 

否則它假定腳本標籤以外的東西不是JavaScript

而且使用小寫的事件,最好使用addEventListener

0

<!DOCTYPE HTML> 
 
     <html> 
 
     <head> 
 
     <meta charset="utf-8"> 
 
     <title>Chapter11-1</title> 
 

 
     </head> 
 
     <body> 
 
     <div id="banner_logo"><img src="chapter11-1banner.jpg" width="745" height="150" alt="banner" id="banner" /></div> 
 
     <table class="centerItems"> 
 
     \t <tr> 
 
     \t <td> 
 
     \t <a href="#"> 
 
     \t <img src="chapter11-1home_up.gif" id="home" alt="home" onMouseOver="overButton('home')" onMouseDown="downButton('home')" onMouseOut="upButton('home')" onMouseUp="upButton('home')" /></a> 
 
     \t </td> 
 
\t \t \t </tr> 
 
\t \t </table> 
 
     </body> 
 
\t \t <script> 
 
\t \t \t function overButton(img) { 
 
     \t buttonImg="chapter11-1"+img+"_over.gif"; 
 
     \t document.getElementById(img).src=buttonImg; 
 
     \t } 
 
     
 
     \t function downButton(img) { 
 
     \t buttonImg="chapter11-1"+img+"_down.gif"; 
 
     \t document.getElementById(img).src=buttonImg; 
 
     \t } 
 
     
 
     \t function upButton(img) { 
 
     \t buttonImg="chapter11-1"+img+"_up.gif"; 
 
     \t document.getElementById(img).src=buttonImg; 
 
     \t } 
 
     </script> 
 
     </html>