我正在使用这个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 = "";
输入与 p 等元素略有不同,其中 innerHTML 会按您的预期工作。 http://www.w3schools.com/jsref/prop_text_value.asp
关于javascript - 如何更改输入框的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42034417/