The textarea input box expands with the height and content

	方法一(jquery):
	
	$('textarea').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';
	});
	
	方法二:
	
	function setHeight(element) {
    
    
	  $(element).css({
    
    'height':'auto','overflow-y':'hidden'}).height(element.scrollHeight);
	}
	$('textarea').each(function () {
    
    
	  setHeight(this);
	}).on('input', function () {
    
    
	  setHeight(this);
	});

Insert picture description here

Insert picture description here

Here is the quote: https://www.cnblogs.com/GoCircle/p/9759252.html

Guess you like

Origin blog.csdn.net/qq_31182399/article/details/107712055