插件使用:print.js演示

基本演示

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文件打印</title>
    <script src="https://printjs-4de6.kxcdn.com/print.min.js"></script>
    <style href="https://printjs-4de6.kxcdn.com/print.min.css"></style>
    <style>
        *{
            margin:0;
            padding:0;
        }
        #app{
            margin: 20px auto 0;
            width:600px;
            height:1200px;
            background:#f7f7f7;
        }
        table{
            text-align: center;
        }
        table tr{
            width:100%;
            height:40px;
            line-height: 40px;
        }
 
    </style>
</head>
<body>
    <button>点击打印</button>
    <div id="app" >
        <table width="600" height="1200" cellspacing="0" border="1px" align="center"
        bordercolor="#666"  >
            <thead height="60">
                 <tr align="center">
                    <th>姓名</th><th>联系方式</th><th>性别</th>
                 </tr>
            </thead>
            <tbody>
                 <tr align="center">
                    <td>张三</td>
                    <td>110</td>
                    <td>男</td>
                 </tr>
                 <tr align="center">
                    <td>李四</td>
                    <td>110</td>
                    <td>男</td>
                 </tr>
                 <tr align="center">
                    <td>王五</td>
                    <td>110</td>
                    <td>男</td>
                 </tr>
                 <tr align="center">
                    <td>赵六</td>
                    <td>110</td>
                    <td>女</td>
                 </tr>
            </tbody>
        </table>
    </div>
    <script>
        const app = document.querySelector('#app');
        const btn = document.querySelector('button');
 
        btn.onclick = function(){
            printJS({
                printable:'app',
                type:'html',
                documentTitle:'公司文档',
                header:`<header style="color:red;height:60px;text-align:center;">仙古梦回</header>`,
            })
        }
    </script>
</body>
</html>

jQuery打印插件 jQuery.print是一个用于打印页面特定部分的插件 用法 导入jQuery后将其包含在HTML中,如: < script type = “ text / JavaScript ” src = “ path / to / jquery.print.js ” > </ script > 使用它像: $(“#myElementId ”)。print(/ * options * /); 要么 $。print(“#myElementId ” / *,options * /); 您可以提交选项对象,如: $(“#myElementId ”)。print({ globalStyles : 是的, mediaPrint : false, stylesheet : null, noPrintSelector : “。 no -print ”, iframe : 是的, append : null, 前置: null, manualCopyFormValues : true, 延期: $。延期(), 超时: 750, title : null, doctype : &#39; <!doctype html> &#39; }); 目前,此插件支持以下选项: globalStyles 默认: true 可接受的值:布尔值 功能:是否应包含父文档中的样式 mediaPrint 默认: false 可接受的值:布尔值 功能:是否应包含带有media =&#39;print&#39;的链接标签; 由globalStyles选项覆盖 样式表 默认: null 可接受的值:URL字符串 功能:要包括的外部样式表的URL noPrintSelector 默认: ".no-print" 可接受的值:任何有效 jQuery-selector 功能:要从打印中排除的项目的选择器 IFRAME 默认值:true,如果传递no-vaild iframe选择器,则创建隐藏的iframe 可接受的值:任何有效jQuery-selector或布尔值 功能:是否从iframe打印而不是弹出窗口; 可以将jQuery-selector现有iframe作为值 附加/添加 默认: null 可接受的值:任何有效jQuery-selector或HTML文本 功能:在选定内容之前(前置)或之后(追加)添加自定义HTML manuallyCopyFormValues 默认: true 可接受的值:布尔值 功能:是否应将用户更新的表单输入值复制到打印的标记上(这可以通过手动迭代每个表单元素来完成) 延期的 默认: $.Deferred() 可接受的值:任何有效的jQuery.Deferred对象 功能:一旦调用print函数就解析的jQuery.Deferred对象。可用于设置回调 - 请参阅wiki 超时 默认: 750 可接受的值:以毫秒为单位的时间 setTimeout 功能:在创建新窗口/ iframe之前更改等待内容等加载内容的最大时间量,如果新窗口/ iframe 的load事件尚未触发,则作为后备 标题 默认值:null,使用主页标题 可接受的值:任何单行字符串 功能:更改打印的标题 DOCTYPE 默认: &#39;<!doctype html>&#39; Acceptable-Values:任何有效的doctype字符串 功能:将doctype添加到打印的文档框架中
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值