0
我是一個JavaScript初學者。我試圖單擊按鈕來顯示文本,但它不起作用。我試圖創建一個猜謎遊戲,用戶在該字段中輸入一個數字以猜測由JavaScript創建的隨機數。我會感謝您的幫助!JavaScript onClick with Inputfield Not Working
<div class="wrap" >
Project: Guessing Game
<input type="text" name="inputField" value="" id="inputField">
<button id="guess">Guess!</button>
<br>
<p id="output"></p>
</div>
<script type="text/javascript" charset="utf-8">
var $ = function(selector) {
return document.querySelector(selector);
};
// var myNumber = Math.random();
// var randomIntegerRange = function(min,max){
// return Math.round(((Math.random()*(max-min))+min));
// };
// randomIntegerRange(1,4);
var myButton = $("#guess");
var myInput = $("#inputField");
var myOutput = $("#output");
myButton.onClick = function() {
myOutput.innerHTML += "Your number is bigger than the random number";
};
</script>
你在哪裏註冊一個事件監聽器? –
看看這裏的解決方案:http://jsfiddle.net/Q9thB/ – andHapp