2014-06-30 58 views
0
<script> 
    var showCounter = 0 ; 
    var myTimeout ; 
    function myShow() 
    { 
    if (showCounter== 0) ; 
    { 
    document.mypic.src="one.jpg" 
    showCounter =1 
    } 
    else if (showCounter==1) 
    { 
     document.mypic.src="two.jpg" 
     showCounter =2 
     } 
    else if (showCounter==2) ; 
    { 
     document.mypic.src="three.jpg" 
     showCounter =3 
     } 
    else 
    { 
     document.mypic.src="four.jpg" 
     showCounter=0 
    } 
    myTimeout=setTimeout ("myshow()", 1000) 
    } 
    </script> 

<body> 
<img src="one.jpg" 
    name="one" 
    onclick="myShow()"> 

此功能有什麼問題?我通過調試器運行它,無法讓它工作。我也通過其他軟件運行它來驗證,它說這個函數可以工作,但它不運行幻燈片。任何幫助?使用Javascript功能援助,無法獲得提示框出現

+0

歡迎來到Stack Overflow!查看[JavaScript錯誤控制檯](http://www.creativebloq.com/javascript/javascript-debugging-beginners-3122820)並告訴你在那裏看到了哪些錯誤以及它們指向哪些行。 – JJJ

+0

@Juhana - 好吧,看看代碼(幾乎)每一行都是錯誤的? – adeneo

+0

當然,但重點是教導OP自己找到它們。 – JJJ

回答

-1

失蹤「你不能喝酒後和花括號是不一樣的一個正常的支架

+0

這是什麼原因downvote? –

-1
function evaluateAge(){ 
    var userAge = prompt ("Please enter your age", ""); 
    if (userAge >=21){ 
     alert("You can drink"); 
    }else{ 
     alert("You can not drink"); 
    } 
} 
1

一般來說,你會從下面的語義技術中獲益。

  • 始終使一定要有適當的標籤(或者沒有標籤)
  • 當你認爲代碼應該可以工作並且不會檢查括號和分號等事物時
  • 如在上述評論中提及,利用在很多主流互聯網瀏覽器(通常是通過CTRL + SHIFT + I達到)所提供的調試器的代碼

    <script> 
        //were missing a semicolon after "counter" 
        var counter; 
    
        function evaluateAge() 
        { 
         //were missing a semicolon after userAge 
         var userAge; 
    
         //had an unwanted space between 'user' and 'Age' 
         //were missing a semicolon at the end of the line 
         userAge = prompt ("Please enter your age", ""); 
    
         //unwanted space between 'user' and 'Age' 
         //recommend formatting if-else as below to avoid confusion 
         //always doublecheck brackets and semicolons too 
         if (userAge >= 21){ 
          alert("You can drink"); 
         }else{ 
          alert("You can not drink"); 
         } 
        } 
    </script> 
    

    追查錯誤

    <form> 
        <!--for semantics just go with a button tag--> 
        <button type="button" name="drink" id="drink">Evaluate Your Age</button> 
    </form> 
    
    <script> 
        //avoid statements akin to "onclick" in the markup 
        //maintain separation by applying this way: 
        document.getElementById("drink").addEventListener("click",evaluateAge); 
    
        //in general you'd be better to avoid these inline "script" tags 
        //use an external js file instead 
    </script> 
    

+0

\t 這有什麼問題? – user3791013

+0

那裏的代碼有很多錯誤。我的建議是在網絡瀏覽器中運行它,並使用調試器嘗試修復它,如上面的答案中所述。我還會推薦像www.codeacademy.com這樣的網站,您可以在javascript中使用初學者課程。如果我解決了您的問題,請選擇我的答案旁邊的綠色複選標記。 – pooley1994