简体   繁体   English

我可以设置TEXTAREA元素的高度,但以后让用户调整其大小吗?

[英]Can I set height of TEXTAREA element but let user resize it later?

I'm trying to set height of the textarea with JS, by default so to speak, but let user resize it later. 我试图用JS设置textarea高度,可以这么说,默认情况下,但是让用户稍后调整它的大小。 So I use this HTML/CSS/JS: 因此,我使用以下HTML / CSS / JS:

<textarea id="i3" cols="45" rows="5" style="line-height: 1.0;">
</textarea>

var obj = document.getElementById("i3");
if(obj.scrollHeight > obj.offsetHeight)
{
    obj.style.height = obj.scrollHeight + 'px';
}

The issue is that when the textarea is resized the user cannot resize it smaller than the height set by my JS. 问题在于,调整文本区域的大小时,用户无法将其调整为小于我的JS设置的高度。 Is there any way to let user do it? 有什么办法可以让用户做到这一点?

PS. PS。 I need this for Google Chrome only (I'm writing a Chrome Extension.) 我只需要用于Google Chrome浏览器(我正在编写Chrome扩展程序)。

the problem is that you used if condition if(obj.scrollHeight > obj.offsetHeight) according to this browser is not commanded to look when it is smaller so set a condition 问题是您是否使用了如果命令if(obj.scrollHeight > obj.offsetHeight)根据此浏览器的条件, if(obj.scrollHeight > obj.offsetHeight)命令条件较小,则不要求查看该条件

  var obj = document.getElementById("i3");
if(obj.scrollHeight > obj.offsetHeight)
{
    obj.style.height = obj.scrollHeight + 'px';
}  
else if(obj.scrollHeight < obj.offsetHeight)
    {
        obj.style.height = obj.scrollHeight - 'px';
    }

i think it will help but i didn't tried it yet so sorry if I am worng 我认为这会有所帮助,但我还没有尝试过,如果感到不便,抱歉

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

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