让文本域的高度随内容的多少而发生改变,且不会产生滚动条。
<textarea type="text" class="textarea_show" id="description" name="description"></textarea>
$('.textarea_show').each(function () {
this.setAttribute('style', 'height:' + (this.scrollHeight) + 'px;overflow-y:hidden;');
}).on('input', function () {
this.style.height = 'auto';
this.style.height = (this.scrollHeight) + 'px';
});