开发者

How to set a print the contents of the div tag

开发者 https://www.devze.com 2023-02-12 11:10 出处:网络
I have a div tag on my web page which scrolls a long way to the right. I want to create a print button which the user can use to only print the contents in the div tag.

I have a div tag on my web page which scrolls a long way to the right. I want to create a print button which the user can use to only print the contents in the div tag. 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

Then fire it on a click event.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号