https://blog.csdn.net/zZZxiaozhi/article/details/117062010
# HTML代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p id="xz">This is Printer!</p>
<button onclick="printer()">打印</button>
</body>
</html>
# js代码
function printer(){
var newWin = window.open('printer', '', '');
var xiaozhi = document.getElementById("xz").innerText; // 这里的id是要打印的标签里的id
newWin.document.write(xiaozhi);
newWin.document.location.reload();
newWin.print();
newWin.close();
}