我有一个文本区域(自动调整大小),我想清除其所有内容,包括其高度。
到目前为止我已经尝试过:
document.getElementById('textarea').value = '';
Run Code Online (Sandbox Code Playgroud)
和 :
document.getElementById('textarea').attribute('rows','1');
Run Code Online (Sandbox Code Playgroud)
但两者都不起作用。
编辑 :
我使用 autosize.js 来实现:
<textarea id="post" rows="1" title="Write something..." name="posttxt" placeholder="Write something..." role="textbox" autocomplete="off"></textarea>
Run Code Online (Sandbox Code Playgroud)
您可以使用setAttribute重置style在调整大小期间自动添加的属性:
document.getElementById('reset').onclick = function(){
var textarea = document.getElementById('target');
textarea.setAttribute('style','');
textarea.value = "";
}Run Code Online (Sandbox Code Playgroud)
<textarea id="target" rows="1" cols="10"></textarea>
<br>
<button id="reset">Reset</button>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5117 次 |
| 最近记录: |