/* 打印 方法 */
function doPrint() {
console.log('doPrint')
bdhtml = window.document.body.innerHTML;
sprnstr = "<!--startprint-->";
eprnstr = "<!--endprint-->";
console.log(sprnstr);
prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
if (!prnhtml) {
mu.showLoading({
title: '暂无可打印内容'
})
return;
}
window.document.body.innerHTML = prnhtml;
printStart();
window.print();
window.document.body.innerHTML = bdhtml;
printEnd();
// 刷新页面
}
function printStart() {
var arr = getClass(document, "opy")
arr.forEach((item, index) => {
item.classList.add('opy-0')
})
var arr1 = getClass(document, "inpu")
arr1.forEach((item, index) => {
item.classList.remove('bt')
})
}
function printEnd() {
var arr = getClass(document, "opy")
arr.forEach((item, index) => {
item.classList.remove('opy-0')
})
var arr1 = getClass(document, "inpu")
arr1.forEach((item, index) => {
item.classList.add('bt')
})
}
function getClass(oParent, classname) {
var oChild = oParent.getElementsByTagName('*');
var arr = [];
for (var i = 0, len = oChild.length; i < len; i++) {
if (oChild[i].className.indexOf(classname) >= 0) {
arr.push(oChild[i]);
}
}
return arr;
}
发表评论 取消回复