在javascript中重置textarea高度 [英] Reset textarea height in javascript

查看:30
本文介绍了在javascript中重置textarea高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 textarea(自动调整大小),我想清除其所有内容,包括其高度.

I have a textarea (auto resizing) and I want to clear all of its contents including its height.

到目前为止我已经尝试过:

So far I've tried:

document.getElementById('textarea').value = '';

还有:

document.getElementById('textarea').attribute('rows','1');

但两者都不起作用.

我使用 autosize.js :

I use autosize.js with this :

<textarea id="post" rows="1" title="Write something..." name="posttxt" placeholder="Write something..." role="textbox" autocomplete="off"></textarea>

推荐答案

您可以使用 setAttribute 来重置在调整大小期间自动添加的 style 属性:

You could use setAttribute to reset style attribute added automatically during the resize :

document.getElementById('reset').onclick = function(){
    var textarea = document.getElementById('target');
  
    textarea.setAttribute('style','');
    textarea.value = "";
}

<textarea id="target" rows="1" cols="10"></textarea>
<br>
<button id="reset">Reset</button>

这篇关于在javascript中重置textarea高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆