js打印

<iframe id="iframes" style="width: 100%;height: 100%;display: none;page-break-after:always;"></iframe>
$(document).on('click',".form2_dayin",function (e) {
 bdhtml=$(this).parents('.gldayinbiao').html();
    sprnstr="<!--startprint-->"; //开始打印标识字符串有17个字符
    eprnstr="<!--endprint-->"; //结束打印标识字符串
    prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); //从开始打印标识之后的内容
    prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); //截取开始标识和结束标识之间的内容
    // 生成并打印ifrme
    var iframe = document.getElementById("iframes");
    var iwindow = iframe.contentWindow;//获取iframewindow对象
    iwindow.document.body.innerText = "";//先清空iframe原先的内容
    iwindow.document.write(prnhtml);
    iwindow.print(); //调用浏览器的打印功能打印指定区域
})

猜你喜欢

转载自blog.csdn.net/qq_37164847/article/details/80771404