How would I change the content of a <textarea> element with JavaScript?(如何使用JavaScript更改<textarea>元素的内容?)
<textarea>
I want to make it empty.(我想把它清空。)
Like this:(像这样:)
document.getElementById('myTextarea').value = '';
or like this in jQuery:(或在jQuery中这样:)
$('#myTextarea').val('');
Where you have(你在哪里)
<textarea id="myTextarea" name="something">This text gets removed</textarea>
For all the downvoters and non-believers:(对于所有反对者和非信奉者:)
Here's the MSDN reference(这是MSDN参考)
value Property: Retrieves or sets the text in the entry field of the textArea element.(value属性:在textArea元素的输入字段中检索或设置文本。)
Here's the MDN reference(这是MDN参考)
value DOMString The raw value contained in the control.(value DOMString控件中包含的原始值。)
1.4m articles
1.4m replys
5 comments
56.9k users