js 触发打印操作

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>
    <button onclick="clickHandler()">print</button>
    <script>
      function clickHandler() {
        if (typeof window.print === "function") {
          window.print();
        } else {
          alert("您的设备不支持打印操作");
        }
      }
    </script>
  </body>
</html>

posted on 2021-09-09 10:33  aisowe  阅读(168)  评论(0编辑  收藏  举报

导航