js,简单的打印例子

Posted qaakd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js,简单的打印例子相关的知识,希望对你有一定的参考价值。

<body>
  
  <input type="button" value="打印此页面" οnclick="printpage()" />
  <div id="printContent">打印内容</div>
 
  <script>
    function printpage() {
      let newstr = document.getElementById("printContent").innerhtml;
      let oldstr = document.body.innerHTML;
      document.body.innerHTML = newstr;
      window.print();
      document.body.innerHTML = oldstr;
      return false;
    }
  </script>
</body>

以上是关于js,简单的打印例子的主要内容,如果未能解决你的问题,请参考以下文章