简体   繁体   English

如何设置打印div标签的内容

[英]How to set a print the contents of the div tag

I have a div tag on my web page which scrolls a long way to the right. 我的网页上有一个div标签,该标签向右滚动很长一段时间。 I want to create a print button which the user can use to only print the contents in the div tag. 我想创建一个打印按钮,用户只能用来打印div标签中的内容。 Thanks for any help with this. 感谢您对此的任何帮助。

Something like this 像这样

<html>
    <head>
        <style>
        @media print {
            .noprint {
                display: none;
            }
        }
        </style>
    </head>

    <body>

        <div class="noprint">
        Would not print
        </div>

        <div>
        This would print
        </div>

        <div class="noprint">
        Would not print
        </div>

    </body>
</html>

If you want a javascript based solution and you use jquery you can use this plugin: http://plugins.jquery.com/project/jqPrint 如果您需要基于JavaScript的解决方案并且使用jquery,则可以使用以下插件: http : //plugins.jquery.com/project/jqPrint

Then fire it on a click event. 然后在点击事件上触发它。

$('#elementToClickOn').click(function() {
  $("#divToPrint").jqprint();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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