有时候需要根据自己的要求打印网页,此时就不能直接利用浏览器的打印了,要用JavaScript控制打印网页的内容,具体实现如下:

function PrintTest(){

    var history = document.body.innerHTML;
    document.body.innerHTML = document.getElementById(“Test”).innerHTML;
    window.print();
    document.body.innerHTML = history;
    window.location.reload();

}

 

<button onclick="PrintTest()"></button>
<div >

//打印内容

</div>

 

相关文章:

  • 2021-09-17
  • 2022-12-23
  • 2021-12-12
  • 2021-09-30
  • 2022-12-23
  • 2021-11-05
猜你喜欢
  • 2022-01-23
  • 2021-08-06
  • 2021-11-18
  • 2021-11-18
  • 2021-05-13
相关资源
相似解决方案