简体   繁体   English

如何更改输入框的文本?

[英]How can I change the text of a input box?

I'm using this JS to try to set the text of a input box to nothing when the user clicks the clear button 我正在使用此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 = "";

Here is the HTML I used for the input box and clear button: 这是我用于输入框和清除按钮的HTML:

<input id="input" type="text">

<button onclick="clearText()">Clear Factors</button>

What could I have done wrong? 我做错了什么?

Try out input.value = ""; 试用input.value = ""; Inputs are a little different then an element such as ap where the innerHTML would work as you expect. 输入与诸如ap之类的元素略有不同,在该元素中,innerHTML将按预期工作。 http://www.w3schools.com/jsref/prop_text_value.asp http://www.w3schools.com/jsref/prop_text_value.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM