本文主要是介绍window.print 页面打印,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>打印测完</title> <meta name="description" content=""> <meta name="keywords" content=""> <link href="" rel="stylesheet"> <style> #oDiv2 div{width: 100px;height: 100px;border:1px solid #c50000;} </style> </head> <body> <div>aaa</div> <div id='oDiv2'><div>bbb</div></div> <div>ccc</div> <input type="button" value="打印" id="js_print" /> <script> var oPrintBtn = document.getElementById("js_print"); var oDiv2 = document.getElementById("oDiv2"); oPrintBtn.οnclick=function(){ var oPop = window.open('','oPop'); var str = '<!DOCTYPE html>' str +='<html>' str +='<head>' str +='<meta charset="utf-8">' str +='<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">' str+='<style>'; str+='#oDiv2 div{width: 100px;height: 100px;border:1px solid #c50000;}'; str+='</style>'; str +='</head>' str +='<body>' str +="<div id='oDiv2'><div>bbb</div></div>"; str +='</body>' str +='</html>' oPop.document.write(str); oPop.print(); oPop.close(); } </script> </body> </html>
这篇关于window.print 页面打印的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!