You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
klhis/hcemr_new/test.html

56 lines
1.3 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../watscript/jquery-1.9.0.min.js"></script>
</head>
<body id="printPage">
<input type="button" value="打印" class="print">
<script>
//定义打印前事件
var beforePrint = function () {
console.log("打印前");
};
//定义打印后事件
var afterPrint = function () {
console.log("打印后");
}
//监听window状态
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
//为印添加事件
mediaQueryList.addListener(function (mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
//打印前事件
window.onbeforeprint = beforePrint;
//打印后事件
window.onafterprint = afterPrint;
//执行打印
$(".print").click(function () {
$(".print").hide()
var newstr = document.getElementById("printPage").innerHTML;
window.print();
$(".print").show()
})
</script>
</body>
</html>