2016-11-28 74 views
0

我不想再問,但我仍然habeing問題機智我的代碼fo4r我的紅綠燈我已經修改了一些,但仍存在例如按鈕不會出現一些問題,我我在Dreamweaver中編程,代碼是html。HTML紅綠燈仍然失敗,使用Dreamweaver

<p>This is my Traffic Light script</p> 

<img id="image" src="RedLight.jpg"; 

<button type="button" onclick="changeLights()">Change Lights</button> 

</head> 

<body> 
<script> 
var list=["RedLight.jpg","RedAmberLight.jpg","GreenLight.jpg","AmberLight.jpg"] 

var lighton = "Red" 

function changeLights() { 

    if (lighton=="Red") { 
     image.src=list[1]; 
    lighton="RedAmber";} 


    if (lighton=="RedAmber") { 
     image.src=list[2]; 
    lighton="Green";} 


    if (lighton=="Green") { 
     image.src=list[3]; 
    lighton="Amber";} 


    else{ 
     image.src=list[3]; 
    lighton="Red";} 

} 
</script> 
</body> 
</html> 
+0

修復這一行:'' – Banzay

+0

和''移動你的代碼到'' – Banzay

+0

仍然不顯示圖像,以便仍然沒有工作不知道是什麼問題在於按鈕出現,並且在其中存在交叉的框也是如此 –

回答

0

這裏是一個解決方案:

<body> 

<p>This is my Traffic Light script</p> 

<img id="image" src="RedLight.jpg"> 

<button type="button" onclick="changeLights()">Change Lights</button> 

<script> 
var list=["RedLight.jpg","RedAmberLight.jpg","GreenLight.jpg","AmberLight.jpg"] 
var lighton = "Red" 
function changeLights() { 
    if (lighton=="Red") { 
     document.getElementById("image").src = list[1]; 
     lighton="RedAmber"; 
    } 
     else if (lighton=="RedAmber") { 
      document.getElementById("image").src=list[2]; 
      lighton="Green"; 
     } 
      else if (lighton=="Green") { 
       document.getElementById("image").src=list[3]; 
       lighton="Amber"; 
      } 
      else{ 
       document.getElementById("image").src=list[0]; 
       lighton="Red"; 
      } 
} 
</script> 
</body>