0
此問題可能對此網站不存在,但我不知道在哪裏尋找這樣的內容,所以我很抱歉,如果是這樣。如何將textarea擴展爲其內容並禁用使用CSS和jQuery進行手動調整大小
所以我在Google窗體上製作了一個帶有長答案問題的dummy test form,我試圖弄清楚文本區域如何隨其內容擴展,但禁用了調整大小。由於我增加了超過300個字符的文本數量,最後一行文本和textarea
的底部之間出現了差距,粘貼文本多次只增加了空間量。我的猜測是,谷歌計算文本的aproximative高度使用平均的字符擬合在一條線上的字符數量與textarea
框中寫入的字符數量。
所以我想知道是否有更準確地檢測在textarea
線的數量和谷歌的形式一樣調整它的高度的方式
我想(但也許更好?):
- 也許每個字母都有一個精確的單獨寬度和 然後計算下一個字母是否適合該行。
- 也許有一個隱藏的視圖div具有相同的寬度和相同的 文本樣式並將文本快速複製到div,然後將 div的偏移高度複製到textarea?
- 也許我想念你們可能知道的東西?
讓我知道你的tough!!
你怎麼樣計算行數textarea的身高[這](http://stackoverflow.com/questions/2035910/how-to-get-the-number-of -lines-in-a-textarea)可能會有所幫助,至於禁用調整大小請看看[this](http://stackoverflow.com/questions/5235142/how-to-disable-resizable-property-of-textarea ) – mbeso
我的'textarea'有一個固定的'width'和'height',並且'resize:none;'所以我不能使用像height這樣的東西。我正在計劃使用這些信息更新身高。在引用帖子中使用的String.prototype.lineCount()僅返回1.我希望行數包括通過包裝文本創建的行。就像我在Google表格上的示例 –
這個JSfiddle可能是一個很好的解決方案! http://jsfiddle.net/Mottie/PfD7L/100/ –