Yii2PHP经验分享

YII2打印机打印DIV(非jquery.jqprint方法)

2019-08-27  本文已影响0人  ZeroScience

项目中具有打印“售后工单表”的功能,YII2中没有直接的方法或扩展使用(暂时没有找到)。网上找到jquery.jqprint是jQuery的插件。但由于我的项目中采用了3.0.1以上的版本,在试验中因为加载两个jquery的原因,不能正常打印。网上的例子在脱离此项目时单独可以使用。

采取以下办法,打印DIV到打印机。页眉还没有去除。

<html>
<head>
<script language="javascript">
    function printdiv(printpage)
    {
        var headstr = "<html><head><title></title></head><body>";
        var footstr = "</body>";
        var newstr = document.all.item(printpage).innerHTML;
        var oldstr = document.body.innerHTML;
        document.body.innerHTML = headstr+newstr+footstr;
        window.print(); 
        document.body.innerHTML = oldstr;
        return false;
    }
    </script>
    <title>div打印</title>
</head>

<body>
    <input name="b_print" type="button" class="ipt" onClick="printdiv('div_print');" value=" Print ">
    <div id="div_print">
        <h1 style="Color:Red">The Div content which you want to print</h1>
    </div>
</body>

</html>
上一篇 下一篇

猜你喜欢

热点阅读