0
問:爲什麼我無法將輸入文本#userGuess
的值存入變量userInput
?從輸入文本中獲取數據到變量
下面是HTML
<div class="row-fluid">
<div class="span12" style="text-align:center">
<form>
<fieldset>
<legend>Guessing Game</legend>
<label>Input a number in your mind</label>
<input type="text" id="userGuess" auto-complete="off">
<span class="help-block" style="display:block">
<p class="help-block" id="resultWaiting" style="display:block">Results!</p>
<p class="help-block" id="resultWarmer" style="display:none; color:#E61010">Warmer!</p>
<p class="help-block" id="resultColder" style="display:none; color:#104CE6">Brr! Colder</p>
<p class="help-block" id="resultCorrect" style="display:none; color:#E61010">YES! YOU GOT IT</p>
</span>
<button type="submit" id="submitButton" class="btn">Submit</button>
<button class="btn btn-danger" type="button">Show Result</button>
</fieldset>
</form>
</div>
</div>
這裏是javascript代碼
$("#submitButton").click(submit);
function submit() {
var userInput = $('#userGuess').val();
if (userInput == pcRandom) {
$("#resultWaiting").css("display","none");
$("#resultCorrect").css("display","block");
} else{
compare(userInput, pcRandom);
}
}
雖然在Chrome開發工具調試,它只是說userInput變量是不確定的。
我用引導的CSS框架和jQuery
應,最佳實踐,不是必須的。 JavaScript在內部對其進行了組織:http://jsfiddle.net/uJDnd/ – Robert
沒有看到任何代碼問題。它的工作很好http://jsfiddle.net/amantur/CUDJR/ – TheVillageIdiot
注意:@TheVillageIdiot已取出