StackOverflow にあるこのスクリプトを使用して、すべてのコンテンツを含む div を出力しています。
<script>
$(document).ready(function(){
$('#printmodal').click(function(){
// variables
var contents = $('#content').html();
var frame = $('#printframe')[0].contentWindow.document;
// show the modal div
$('#modal').css({'display':'block'});
// open the frame document and add the contents
frame.open();
frame.write(contents);
frame.close();
//Hide all 'noprint' elements
$(".noprint").css("display","none");
// print just the modal div
$('#printframe')[0].contentWindow.print();
// hide the modal div
$('#modal').css({'display':'none'});
});
});
</script>
ただし、印刷したくない要素がいくつかあります。ボタンなど。これらの要素には、「noprint」というクラス名が付けられています。media="print" css がありますが、上記の関数を使用しても機能しません。noprint 要素はまだ印刷中です。$(".noprint").css("display", "none"); を追加してみました。関数ですが、それでもそれらの要素を出力します。上記の機能を使用しているときに特定の要素を印刷しないようにする方法を知っている人はいますか?