如何使用jQuery在其內容(如Facebook中)中自動調整大小<textarea>
。textarea在jquery中自動調整大小
2
A
回答
2
2
<script type="text/javascript">
function adjustTextarea(this_){
var value_ = this_.value;
value_ = value_.replace(new RegExp("\n\r", 'gi'), "\n");
value_ = value_.replace(new RegExp("\r", 'gi'), "\n");
var split_ = value_.split("\n");
this_.rows = split_.length;
return;
}
</script>
<textarea cols="100" style="overflow:hidden;" onkeyup="adjustTextarea(this);" onfocus="adjustTextarea(this);" >
Text
</textarea>
+0
純JavaScript的絕佳解決方案! – B4NZ41 2014-03-18 16:21:21
0
使用詹姆斯Padolsey自動調整jQuery插件從http://james.padolsey.com/javascript/jquery-plugin-autoresize/
基本用法
$('textarea#comment').autoResize({
// On resize:
onResize : function() {
$(this).css({opacity:0.8});
},
// After resize:
animateCallback : function() {
$(this).css({opacity:1});
},
// Quite slow animation:
animateDuration : 300,
// More extra space:
extraSpace : 40
});
0
超輕:
有沒有人認爲contented?沒有搞亂滾動,只有我喜歡它的JS是如果你打算將數據保存在模糊上...顯然,它在所有流行的瀏覽器兼容:http://caniuse.com/#feat=contenteditable
只是它的樣式它看起來就像一個文本框,它會自動調整大小......使其最小高度成爲首選文本高度並且具有它。
這種方法最酷的是你可以在某些瀏覽器上保存和標記。根據什麼
http://jsfiddle.net/gbutiri/v31o8xfo/
<style>
.autoheight {
min-height: 16px;
font-size: 16px;
margin: 0;
padding: 10px;
font-family: Arial;
line-height: 16px;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
overflow: hidden;
resize: none;
border: 1px solid #ccc;
outline: none;
width: 200px;
}
</style>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
$(document).on('blur','.autoheight',function(e) {
var $this = $(this);
// The text is here. Do whatever you want with it.
console.log($this.html());
});
</script>
<div class="autoheight contenteditable" contenteditable="true">Mickey <b>Mouse</b></div>
相關問題
- 1. Textarea寬度自動調整大小
- 2. HTML textarea不會自動調整大小
- 3. Textarea垂直大小和自動調整
- 4. HTML TextArea自動調整大小
- 5. Textarea自動調整大小在每個按鍵上調整大小鉻
- 6. Textarea調整大小
- 7. 回調jquery手機textarea調整大小
- 8. 自動調整大小textarea鏈接關閉jquery
- 9. jQuery Mobile textarea調整大小問題
- 10. 在動態創建的textarea上自動調整大小
- 11. Textarea在ie中調整垂直大小
- 12. Textarea滾動時調整大小
- 13. Textarea調整窗口大小
- 14. Extjs5 textarea的大小調整
- 15. 調整大小textarea的
- 16. 用jquery自動調整圖像大小
- 17. jquery輸入自動調整大小
- 18. 調整大小在textarea的字體不增加textarea的大小
- 19. Gridpanel在調整窗口大小時自動調整大小
- 20. 在屏幕上自動調整圖像大小調整大小
- 21. 在窗口調整大小時自動調整圖像大小
- 22. 在Xcode 8中自動調整大小
- 23. DirectShow自動調整大小
- 24. YouTube自動調整大小
- 25. 自動調整大小JTabbedPane
- 26. GridView自動調整大小
- 27. iframe自動調整大小
- 28. 自動NSView調整大小
- 29. 自動調整大小CCLabelBMFont
- 30. 自動調整大小
自動調整大小?包含元素?窗戶?文本的長度? – 2010-06-01 10:46:54
我認爲你的意思是像默認的Safari/Chrome textarea ...或Facebook上越來越多的textarea? – scunliffe 2010-06-01 10:49:02
就像臉書 我想調整我的文本框的大小,當我在文本框中輸入更多的文字 – picnic4u 2010-06-01 10:53:40