2010-08-04 62 views
1

當一個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

回答

0

我有自動調整大小()爲我在做什麼,所以我的情況下,使用一個稍微不同的方法,我只是張貼問題是別人

我需要的行爲有用的是用它的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(); 
})