自动扩展文本区

问题描述:

当一个textarea中有更多的文本比可以显示它将显示滚动条。我该如何做到这一点,以便textarea在文本数量多于可显示的情况下自行扩展。我的目标是永远不会出现滚动条。 jQuery解决方案是首选。自动扩展文本区

+0

http://stackoverflow.com/questions/1197115/jquery-detecting-when-we-are-at-the-end-of-text-in-textarea – hookedonwinter 2010-08-04 20:40:05

+0

但是,在回答的可能的复制你的问题,http://james.padolsey.com/javascript/jquery-plugin-autoresize/ – hookedonwinter 2010-08-04 20:40:26

这里是一个工作示例:

http://blogs.sitepointstatic.com/examples/tech/textarea-expander/index.html

它包含下载的代码以及执行指令。

http://jacklmoore.com/autosize/

// Example: 
$(document).ready(function(){ 
    $('textarea').autosize();  
}); 

,因为它得到简单。我认为8)。

我有自动调整大小()为我在做什么,所以我的情况下,使用一个稍微不同的方法,我只是张贴问题是别人

我需要的行为有用的是用它的textarea高度在负载上调整大小,并在失去焦点时调整大小(编辑完成)。

function updateAddressHeight() { 
    var lineHeight=16; //Whatever you need 
    address = $("#Address").val() 
    lines = address.split("\n"); 

    $("#Address").height((lines.length * lineHeight)); 
} //funct 

$(document).ready(function(){ 
    $("#Address").change(function() { 
     updateAddressHeight(); 
    }); 

    updateAddressHeight(); 
})