H5齐鲁医疗
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
sims-scaninvoice-qlyl/js/lib/auto-height-textarea.js

39 lines
1.4 KiB

(function () {
const isEmpty = function (value) {
return value.replace(/\s/, '').length > 0;
};
const getStyle = function (element, property) {
if (!!document.defaultView.getComputedStyle) {
return document.defaultView.getComputedStyle(element, null)[property];
} else {
const currentStyle = element.currentStyle;
return currentStyle[property];
}
};
let addEven = function (ele, type, callback) {
if (document.addEventListener) {
addEven = function (ele, type, callback) {
ele.addEventListener(type, callback, false);
};
} else {
addEven = function (ele, type, callback) {
ele.attachEvent('on' + type, callback);
};
}
addEven(ele, type, callback);
};
this.autoTextArea = function (dom) {
if (!(dom && dom.nodeType === 1 && dom.nodeName === 'TEXTAREA')) return;
const diff = parseInt(getStyle(dom, "paddingTop") || 0) + parseInt(getStyle(dom, "paddingBottom") || 0);
if (isEmpty(dom.value)) {
dom.style.height = dom.scrollHeight - diff + "px";
}
addEven(dom,"input", function (e) {
const event = e || window.event;
const target = event.target || event.srcElement;
target.style.height = "0";
target.style.height = target.scrollHeight - diff + "px";
});
};
})();