相关疑难解决方法(0)

使用自动调整大小创建textarea

还有另外一个关于这个问题,我试过了.但是有一个问题:textarea如果删除内容,则不会缩小.我找不到任何方法将它缩小到正确的大小 - clientHeight值返回为完整的大小,而textarea不是其内容.

该页面的代码如下:

function FitToContent(id, maxHeight)
{
   var text = id && id.style ? id : document.getElementById(id);
   if ( !text )
      return;

   var adjustedHeight = text.clientHeight;
   if ( !maxHeight || maxHeight > adjustedHeight )
   {
      adjustedHeight = Math.max(text.scrollHeight, adjustedHeight);
      if ( maxHeight )
         adjustedHeight = Math.min(maxHeight, adjustedHeight);
      if ( adjustedHeight > text.clientHeight )
         text.style.height = adjustedHeight + "px";
   }
}

window.onload = function() {
    document.getElementById("ta").onkeyup = function() {
      FitToContent( this, 500 ) …
Run Code Online (Sandbox Code Playgroud)

html javascript height textarea resize

328
推荐指数
15
解决办法
38万
查看次数

使用jQuery自动扩展textarea

如何使用jQuery自动扩展textarea?

我有一个用于解释会议议程的文本框,所以当我的议程文本不断增加该文本框区域时,我想扩展该文本框.

jquery

127
推荐指数
8
解决办法
17万
查看次数

在Ace Cloud 9编辑器中自动调整内容的高度

我正在尝试将Ace编辑器添加到页面中,但我不知道如何根据其内容的长度自动设置高度.

理想情况下它会起作用,所以当内容改变时,重新计算高度,但我会对页面加载时设置的高度感到满意.

对于JavaScript新手,有人可以帮我弄清楚我如何计算代码的长度,跨越多少行,新高度是什么以及如何更新DOM以反映这一点?

我在谷歌小组中找到了这个建议,但我真的不明白它在做什么以及如何调整高度.

editor.getSession().getDocument().getLength() *
editor.renderer.lineHeight + editor.renderer.scrollBar.getWidth()
Run Code Online (Sandbox Code Playgroud)

javascript ace-editor

61
推荐指数
4
解决办法
4万
查看次数

反正有没有基于页面加载内容的textarea"autofit"高度?

无论如何通过CSS或Javascript根据内容设置textarea的高度?我的CSS中有一个硬编码的高度,但我想要它默认,所以页面加载时没有垂直滚动条?

html javascript css textarea

22
推荐指数
3
解决办法
1万
查看次数

标签 统计

javascript ×3

html ×2

textarea ×2

ace-editor ×1

css ×1

height ×1

jquery ×1

resize ×1