打印选中的网页

 //把需要打印的代码,替换掉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(); })

 

posted @ 2020-05-26 12:56  刘浩2561179983  阅读(157)  评论(0编辑  收藏  举报