easyui textbox多行文本输入框高度根据内容伸缩

  1. 直接上代码
     
    function makeTextArea(fromId){
    	//查找所有textare 方法  添加自适应
    	$("#"+fromId).find('textarea').each(function(index) {
    		//获取ID属性 IE 不支持attachEvent 写法
    		makeExpandingAreaIE(this);
    	});
    }
    
    function makeExpandingAreaIE(el){
    	var setStyle = function(el) {
    		el.style.height = 'auto';
    		el.style.height = el.scrollHeight + 'px';
    		//@Description 设置控件高度属性和textarea一致,避免游览器窗口大小变动时,输入框高度被easyui自动重置的问题 wangwq 2019/5/6 15:49
    		$("input#"+$(el).next().attr("name")).textbox("options").height=el.style.height;
    		$(el).parent("span").css("height",el.style.height);
    		$(el).css({"overflow-y":"hidden","padding-top":2});
    		// console.log(el.scrollHeight);
    	}  
    	var delayedResize = function(el) {  
    		window.setTimeout(function() {  
    				setStyle(el)  
    			},  
    			0);  
    	}  
    	if (el.addEventListener) {  
    		el.addEventListener('input', function() {  
    			setStyle(el)  
    		}, false);  
    		setStyle(el)  
    	}  else if (el.attachEvent) {  
    		el.addEventListener('onpropertychange', function() {  
    			setStyle(el)  
    		});  
    		setStyle(el)  
    	}    
    	if (window.VBArray && window.addEventListener) { //IE9  
    		el.addEventListener("onkeydown", function() {  
    			var key = window.event.keyCode;  
    			if (key == 8 || key == 46) delayedResize(el);  
    
    		});  
    		el.addEventListener("oncut", function() {  
    			delayedResize(el);  
    		}); //处理粘贴  
    	}  
    }

     

你可能感兴趣的:(easyui textbox多行文本输入框高度根据内容伸缩)