js实现textarea自适应高度
2017-07-31 16:18
387 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> #t{ outline:none; border:thin solid rgba(82, 168, 236, 0.8); box-shadow: 0 0 6px rgba(82, 168, 236, 0.6); resize: none; width: 500px; height: 20px; font-size: 16px; } </style> </head> <body> <textarea name="textArea" id="t"></textarea> <script type="text/javascript"> var textArea = document.getElementById('t'); function activeGo() { var scrollHeight = textArea.scrollHeight; var height = textArea.offsetHeight; if(height < scrollHeight){ textArea.style.height = textArea.scrollHeight+'px'; } } textArea.addEventListener('propertychange',activeGo); textArea.addEventListener('input',activeGo); </script> </body> </html>
相关文章推荐
- js实现textarea高度根据内容自适应
- 使用div模拟textarea,实现文本输入框高度自适应(附:js控制textarea实现文本输入框高度自适应)
- js实现textarea高度根据内容自适应
- js实现textarea根据内容大小自适应高度
- jquery/js实现文本框根据输入内容input,textarea自适应高度
- JS_textarea自适应高度
- JS实现iframe自适应高度的方法(兼容IE与FireFox)
- JS实现DIV高度自适应窗口示例
- textarea如何实现高度自适应?
- textarea 无边框无滚动条自适应高度的实现(转)
- div模拟textarea以实现高度自适应实例页面
- 非js实现iframe高度自适应实现
- JS实现自适应高度表单文本框的方法
- JS实现iframe自适应高度的方法(兼容IE与FireFox)
- js 实现2列 div 自适应高度
- Jquery实现textarea根据文本内容自适应高度
- jquery实现textarea 高度自适应 转自http://www.jb51.net/article/61997.htm
- textarea如何实现高度自适应
- Js实现两列div高度自适应
- textarea实现高度自适应