js achieve front-end printing capabilities

 
// Here is a printing method can be called when the click event
dayin = () =>{
// Get the contents of the current page to be printed 
// Here className ( 'print') I gave the area to be printed from the name 
const print = document.getElementsByClassName('print')[0].innerHTML;
// replace the contents of the current page to be printed
document.body.innerHTML = print;
// Print
window.print();
// refresh page
window.location.reload();
}
 
 

Guess you like

Origin www.cnblogs.com/zhanghongkun/p/11313414.html