验证中...
html代码
Raw Copy
<html>
<head>
<title>Html输入文本域Textarea高度根据内容自适应</title>
</head>
<body>
<textarea id="txtaMain" rows="1" width="200"></textarea>
</body>
</html>
js代码
Raw Copy
$.fn.extend({
txtaAutoHeight: function() {
return this.each(function() {
var $this = $(this);
if(!$this.attr('initAttrH')) $this.attr('initAttrH', $this.outerHeight());
setAutoHeight(this).on('input', function() {
setAutoHeight(this);
});
});
function setAutoHeight(elem) {
var $obj = $(elem);
return $obj.css({height: $obj.attr('initAttrH'), 'overflow-y': 'hidden'}).height(elem.scrollHeight);
}
}
});
//调用
$(function() {
$("#txtaMain").txtaAutoHeight();
});

Comment list( 0 )

You need to Sign in for post a comment

Help Search

183227_9af5e6a8_1826025 111910_4d91f001_1826025