我試圖獲取userinput的值,但我的代碼無法正常工作。如何從javascript輸入文本中獲取值
HTML
<body>
<button id="test">test</button>
<form>
<input type="text" id="test1">
</form>
</body>
的javascript:
var text = null;
$(document).ready(function(){
text = $("#test1").value;
$("#test").on("click", testing);
});
function testing(){
console.log("something");
if(text == "top"){
console.log("top");
}
}
的可能重複[jQuery的:試圖獲得的輸入值(http://stackoverflow.com/questions/3788910/jquery-trying-to-get-the-input-value) – Vasu