Print DIV content by JQuery

前端 未结 6 858
无人共我
无人共我 2021-02-06 03:26

suppose i have many div\'s in my page but i want to print the content of specific div using jquery. i found there is a plugin for that.

jQuery Print Element

usin

6条回答
  •  爱一瞬间的悲伤
    2021-02-06 04:08

    There is a way to use this with a hidden div but you have to work abit more with the printElement() function and css.

    Css:

    #SelectorToPrint{
         display: none;
    }
    

    Script:

      $("#SelectorToPrint").printElement({ printBodyOptions:{styleToAdd:'padding:10px;margin:10px;display:block', classNameToAdd:'WhatYouWant'}})
    

    This will override the display: none in the new window you open and the content will be displayed on the print-preview page and the div on you site remains hidden.

提交回复
热议问题