打印整个页面,去除打印按钮
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title></title> <style type="text/css"> * { margin: 0px; padding: 0px; } </style> </head> <body ondragstart="return false"> <div class="zhengshucontent"> <img class="zsbg" src="~/Content/JobInjuryCertManager/Image/zhengshubg.png"> <div class="bainhao">@(certInfo != null && certInfo.Id > 0 ? certInfo.CertNumber : "")</div> <div class="photo"> <img src="@(certInfo != null && certInfo.Id > 0 ? certInfo.PhotoUrl : "")"> </div> <div class="center"> <div class="name">@(certInfo != null && certInfo.Id > 0 ? certInfo.Name : "")</div> <div class="idnumber">@(certInfo != null && certInfo.Id > 0 ? certInfo.PersonalId : "")</div> </div> <div class="bottombox"> <div class="jigou">@(certInfo != null && certInfo.Id > 0 ? certInfo.DepartmentName : "")</div> <div class="yearmonnthday"><span>@(certInfo != null && certInfo.Id > 0 ? certInfo.CreateTime.ToString("yyyy") : "")</span><span>@(certInfo != null && certInfo.Id > 0 ? certInfo.CreateTime.ToString("MM") : "")</span><span>@(certInfo != null && certInfo.Id > 0 ? certInfo.CreateTime.ToString("dd") : "")</span></div> </div> <div class="erweima"> <img src="@(certInfo != null && certInfo.Id > 0 ? certInfo.ErWeiMa : "")"> </div> </div> <!--endprint--> <button onclick="printCert()">打印</button> </body> </html> <script> function printCert() { var eprnstr = "<!--endprint-->"; var oldstr = document.body.innerHTML; var newstr = oldstr.substring(0, oldstr.indexOf(eprnstr)); document.body.innerHTML = newstr + "</body></html>"; window.print(); document.body.innerHTML = ""; document.body.innerHTML = oldstr; } </script>