打印选中的网页

 //把需要打印的代码,替换掉body中的内容,执行window.print()方法
document.getElementsByTagName("body")[0].style.overflow='auto' // this.$print(this.$refs.print) var arr=document.getElementsByClassName('v-transfer-dom') arr.forEach(function(item){ item.style.display='none' }) var tables=document.getElementsByTagName('table'); tables.forEach(function(item){ item.style.width='100%' item.setAttribute('width','100%'); }) var td=document.getElementsByTagName('td'); td.forEach(function(item){ item.style.width='auto' item.setAttribute('width','auto'); }) setTimeout(function(){ document.getElementById('app1').innerHTML="" document.getElementById('app1').appendChild((document.getElementById('print').cloneNode(true))) window.print(); window.location.reload(); })
原文地址:https://www.cnblogs.com/liuhao-web/p/12858090.html