[英]How to get text from a text box in JS
以下代碼不起作用
<!DOCTYPE html>
<html>
<body>
<input type="text" id="searchTxt"/>
<input type="button" id="run"/>
<script>
$(document).ready(function() {
$("#run").click(function(){
var input = document.getElementById("searchTxt");
alert(input);
});
});
</script>
</body>
</html>
如何獲取並在文本框中打印值?
您必須在<head>
標記內包含jQuery JS文件。
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
getElementById函數返回的元素上的.value
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.