有时候需要根据自己的要求打印网页,此时就不能直接利用浏览器的打印了,要用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 id="Test"> //打印内容 </div>