ES6教程

ES6 页面打印

ES6 页面打印

在某些情况下,需要在网页上放置一个按钮,使用实际打印机打印网页内容。 JavaScript 帮助我们实现打印网页。
当打印功能执行 JavaScript 中的 window.print(),然后打印当前网页。我们可以直接在onclick事件中直接调用这个函数。
语法
window.print();
示例
<html> 
  
<head>  
</head> 
  
<body> 
    <center> 
        <h1>Hello World :) :)</h1> 
        <h2>Welcome to lidihuo</h2> 
        <h2>Click the following print button to see the changes</h2> 
        <input type = "button" value = "Print" onclick = "window.print()"/>
    </center> 
</body> 
  
</html>
输出
成功执行以上代码后,会得到如下输出:
ES6 Page Printing
当您点击打印按钮时,您将看到以下屏幕:
ES6 页面打印
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4