js打印指定内容

 1 function printme() { 
 2      var mycss='<link rel="stylesheet" href="css/style.css" type="text/css" >';
 3      var id_str=mycss+$(my_title).html()+$(my_content).html();
 4      var iframe = document.createElement('IFRAME');
 5      var doc = null;
 6      //  iframe.setAttribute('style', 'position:absolute;0px;height:0px;left:-500px;top:-500px;');
 7      document.body.appendChild(iframe);
 8      doc = iframe.contentWindow.document;
 9      doc.write('<div>' + id_str + '</div>');
10      doc.close();
11      iframe.contentWindow.focus();
12      iframe.contentWindow.print();
13      document.body.removeChild(iframe);
14 }
15     

父窗口中,点击打印按钮后,弹出打印内容。

原文地址:https://www.cnblogs.com/wqing/p/2988299.html