在前端页面调用本地打印机的实现:
点击打印之后调出打印机
代码实现:
# 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();
}