简体   繁体   中英

javascript to print contents of only specific <div>

我试过javascript window.print()它打印整页内容,包括页面上的打印按钮。

You require to create new style sheet print.css and set CSS media=print

for example :

<style media="screen">
  .noPrint{ display: block; }
  .yesPrint{ display: block !important; }
</style>

<style media="print">
  .noPrint{ display: none; }
  .yesPrint{ display: block !important; }
</style>

for more detail : Print a doument with CSS

List Apart有一篇非常好的文章。

Create an iframe and copy your text into it. then you can call the print-function of this, in the iframe embedded window

or

see: String.print()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM