El cuadro de entrada del área de texto se expande con la altura y el contenido

	方法一(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);
	});

Inserte la descripción de la imagen aquí

Inserte la descripción de la imagen aquí

Aquí está la cita: https://www.cnblogs.com/GoCircle/p/9759252.html

Supongo que te gusta

Origin blog.csdn.net/qq_31182399/article/details/107712055
Recomendado
Clasificación