jquery实现textarea 高度自适应
作者:bea
之前给大家分享过用Javascript控制文本框textarea高度随内容自适应增长收缩,今天花了点时间换了种实现方法,总结一下 代码如下: jQuery.fn.extend({ autoHeight: function(){ return this.each(function(){ var $this = jQuery(this); if( !$this.attr('_initAdjustHeight') ){ $this.attr('_initA
之前给大家分享过用Javascript控制文本框textarea高度随内容自适应增长收缩,今天花了点时间换了种实现方法,总结一下
代码如下:
jQuery.fn.extend({
autoHeight: function(){
return this.each(function(){
var $this = jQuery(this);
if( !$this.attr('_initAdjustHeight') ){
$this.attr('_initAdjustHeight', $this.outerHeight());
}
_adjustH(this).on('input', function(){
_adjustH(this);
});
});
/**
* 重置高度
* @param {Object} elem
*/
function _adjustH(elem){
var $obj = jQuery(elem);
return $obj.css({height: $obj.attr('_initAdjustHeight'), 'overflow-y': 'hidden'})
.height( elem.scrollHeight );
}
}
});
// 使用
$(function(){
$('textarea').autoHeight();
});
以上就是本文所述的全部内容了,希望对大家学习jQuery能够有所帮助。
有用 | 无用
代码如下:
jQuery.fn.extend({
autoHeight: function(){
return this.each(function(){
var $this = jQuery(this);
if( !$this.attr('_initAdjustHeight') ){
$this.attr('_initAdjustHeight', $this.outerHeight());
}
_adjustH(this).on('input', function(){
_adjustH(this);
});
});
/**
* 重置高度
* @param {Object} elem
*/
function _adjustH(elem){
var $obj = jQuery(elem);
return $obj.css({height: $obj.attr('_initAdjustHeight'), 'overflow-y': 'hidden'})
.height( elem.scrollHeight );
}
}
});
// 使用
$(function(){
$('textarea').autoHeight();
});
以上就是本文所述的全部内容了,希望对大家学习jQuery能够有所帮助。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- jquery利用命名空间移除绑定事件的方法
- jQuery实现带动画效果的二级下拉导航方法
- jquery图形密码实现方法
- jQuery模拟新浪微博首页滚动效果的方法
- jQuery实现在textarea指定位置插入字符或表情的方法
- jQuery实现统计输入文字个数的方法
- jQuery处理json数据返回数组和输出的方法
- jquery实现表格本地排序的方法
- jQuery实现渐变下拉菜单的简单方法
- jQuery实现新消息闪烁标题提示的方法
- javascript实现详细时间提醒信息效果的方法
- JavaScript实现SHA-1加密算法的方法
- JavaScript前补零操作实例
- JavaScript限定图片显示大小的方法
- iScroll中事件点击触发两次解决方案
- node-webkit打包成exe文件被360误报木马的解决方法
- javascript结合Canvas 实现简易的圆形时钟
- 解决node-webkit 不支持html5播放mp4视频的方法
- javascript与css3动画结合使用小结