[英]How can I change the text of a input box?
我正在使用此JS嘗試在用戶單擊清除按鈕時將輸入框的文本設置為空
// This code is not inside of the clearText function
var input = document.getElementById("input");
// this code is inside of the clearText function
input.innerHTML = "";
這是我用於輸入框和清除按鈕的HTML:
<input id="input" type="text">
<button onclick="clearText()">Clear Factors</button>
我做錯了什么?
試用input.value = "";
輸入與諸如ap之類的元素略有不同,在該元素中,innerHTML將按預期工作。 http://www.w3schools.com/jsref/prop_text_value.asp
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.