textarea高度随着内容增加而增加
所属分类: JS 2022-10-26 13:45:15 编辑:admin 浏览次数 799 次
<textarea autoHeight="true">asd</textarea>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
<script>
$(function(){
$.fn.autoHeight = function(){
function autoHeight(elem){
elem.style.height = 'auto';
elem.scrollTop = 0; //防抖动
elem.style.height = elem.scrollHeight+10 + 'px';
}
this.each(function(){
autoHeight(this);
$(this).on('keyup', function(){
autoHeight(this);
});
});
}
$('textarea[autoHeight]').autoHeight();
})
</script>
猜你喜欢
- JavaScript和Jquery的dom操作对比 2018-07-11
- js实现跳转和刷新功能 2018-07-16
- 前端实现分页 2018-07-21
- Js获取当前日期时间及其它操作 2018-08-12
- js为数据加载 2018-08-12
- 正则表达式常用的验证 2018-08-13