股墓山庄

专注于AS3,JavaScript 每天一点进步,坚持...
  博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

js打印指定内容

Posted on 2013-03-29 09:56  股墓山庄庄主  阅读(238)  评论(0编辑  收藏  举报
 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;width: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     

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