0

HTML

<div id="printDiv">
<!-- content Here -->
</div>
<input type="button" value="Print" onclick="printDiv()"/>

JQuery

function printDiv()
{
  $("#printDiv").print();
}

これは、Mozilla Firefox を使用している場合は特定の div を印刷していますが、IE (バージョン 10) を使用している場合は、ページ全体を印刷しています。

このjQueryプラグインを使用しています。

jQuery.print.js

私を助けてください。

4

1 に答える 1

4

プラグインなしでできます。そのプラグインが特別なことをしているかどうかはわかりません。ページ全体ではなくdivのみを印刷するには、カスタムjs関数を作成する必要があります...

html

<div id="printDiv">
       //content Here
 </div>

js

function customPrint(id) {
     var cont = $('#'+id).html(),
         pageCont = $('body').children();// Updated

     /*Replace the page content with the div content that needs to be printed*/
     $('body').html(cont);

     /*Print function call*/
     window.print();

     /*Place the original page content back*/
     $('body').html(pageCont);
}

customPrint("printDiv");

アップデート

function customPrint(id) {
         var cont = $('#'+id),
             pageCont = $('body');

         /*Hide the page content*/
         pageCont.hide();
         cont.show();

         /*Print function call*/
         window.print();

         /*Display back the page content*/
         pageCont.show();
    }
于 2013-09-26T10:25:30.853 に答える