2015-11-24 155 views
-4

我這裏有一些代碼和IM努力找出它去錯了,我知道的一些JavaScript代碼是錯誤的,但我怎麼改正它,非常感謝我的代碼出了什麼問題?

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8" /> 
<title>Numbers Games</title> 
<link rel="stylesheet" type="text/css" href="style-home.css"> 
</head> 

<body> 
<div id="header" 
<h1>Numbers Game</h1> 
</div> 
<p id="ParQuestion">What is five thousand and thirty three in numbers.</p> 
<input id="txt_Ans" type="text" /> 
<input id="btn_Start" type="button" value="Start"     

onclick="btn_Start_OnClick()" /><br /> 
<input id="btn_Check" type="button" value="Check"  onclick="btn_Check_OnlClick()" /> 


<div id="Scoreboard"> 
<img id="scoreOn1" src="Pictures/Scorefaceoff1.gif" height="50px"  width="50px" /> 
<img id="scoreOn2" src="Pictures/Scorefaceoff2.gif" height="50px" width="50px" /> 
<img id="scoreOn3" src="Pictures/Scorefaceoff3.gif" height="50px" width="50px" /> 
<img id="scoreOn4" src="Pictures/Scorefaceoff4.gif" height="50px" width="50px" /> 
<img id="scoreOn5" src="Pictures/Scorefaceoff5.gif" height="50px" width="50px" /> 
</div> 

<p id="ParComment"></p> 

</body> 


</html> 
<script language="javascript"> 

    function btn_Check_OnClick(){ 
     if txt_Ans.value = "5033" 
     parRes.InnerText=ParComment.value; 
    }else{ 
     ParComment.InnerText="Wrong, Try Again"; 
    } 
    } 
</sript> 
+3

歡迎#1。你覺得它是什麼 ?到目前爲止你做了什麼 ?爲了讓我們幫助你證明你做了實際的研究。 :) –

+2

並說了,'btn_Check_onlClick()'?特定函數在哪裏定義?並且在腳本塊中有一個額外的'}'來開始。 –

回答

0

首先你「</sript>」標籤 - > 「</script>

if txt_Ans.value = "5033"」 - > 「if (txt_Ans.value == "5033"){ parRes.InnerText=ParComment.value; }

閉上你的 「DIV標籤」 上線10

編輯:首先,嘗試使用代碼檢查工具如「http://jshint.com/」語法錯誤

1

只是徵求意見的腳本塊:

  • 你關閉標籤說:「sript」,而不是「腳本」
  • 你如果語句有語法錯誤,它缺少(,)和{
  • 您的if語句正在分配它應該進行比較的時間;使用==超過=在條件
  • 該屬性稱爲的innerText,不是的innerText
  • ParComment不具有值屬性
0

我認爲你沒加開腳本標籤。另外,您應該在if語句中添加括號。而不是使用=來比較使用==。此外,使用document.getElementById

試試這個得到的元素:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8" /> 
<title>Numbers Games</title> 
<link rel="stylesheet" type="text/css" href="style-home.css"> 
</head> 

<body> 
<div id="header" 
<h1>Numbers Game</h1> 
</div> 
<p id="ParQuestion">What is five thousand and thirty three in numbers.</p> 
<input id="txt_Ans" type="text" /> 
<input id="btn_Start" type="button" value="Start"     

onclick="btn_Start_OnClick()" /><br /> 
<input id="btn_Check" type="button" value="Check"  onclick="btn_Check_OnlClick()" /> 


<div id="Scoreboard"> 
<img id="scoreOn1" src="Pictures/Scorefaceoff1.gif" height="50px"  width="50px" /> 
<img id="scoreOn2" src="Pictures/Scorefaceoff2.gif" height="50px" width="50px" /> 
<img id="scoreOn3" src="Pictures/Scorefaceoff3.gif" height="50px" width="50px" /> 
<img id="scoreOn4" src="Pictures/Scorefaceoff4.gif" height="50px" width="50px" /> 
<img id="scoreOn5" src="Pictures/Scorefaceoff5.gif" height="50px" width="50px" /> 
</div> 

<p id="ParComment"></p> 

<script> 
    function btn_Check_OnClick(){ 
     if(document.getElementById('txt_Ans').value == "5033"){ 
      parRes.InnerText=ParComment.value; 
     }else{ 
      document.getElementById('ParComment').innerHTML = "Wrong, Try Again"; 
     } 
    } 
</sript> 
</html> 

這是把你的腳本的HTML標籤中

0

有一件事情別人沒有提到的<div id="header"缺少收盤>最佳實踐。不過,你有很多其他人提到的語法錯誤。

通過在瀏覽器開發工具中查看,您將受益匪淺。對於大多數現代瀏覽器,只需按F12打開它們。我相信你可能會在控制檯中顯示一些JavaScript錯誤。這是一個開始的好地方。

爲其他語法錯誤,這裏有幾個地方看看:

相關問題