js 打印(JavaScript 打印 CSS样式)

首先要下载:
jquery.jqprint-0.3.js
jquery-migrate-1.2.1.min.js
上面两个,我的资源里面都有

主要是使用 jquery.jqprint-0.3.js
jquery-migrate-1.2.1.min.js是因为juqery版本兼容问题,会报错Cannot read property 'opera' of undefined问题,加入迁移辅助插件jquery-migrate-1.2.1.min.js可解决问题

注意:打印 table 的时候 一定要把css写成行内样式,要不打印的时候,就不会打印表格样式了。

<button onclick="dayin()">打印</button>
<div id="dayinbufen" style="margin: 0 auto">
  <h2 style="margin-bottom: 20px; text-align: center">打印表格</h2>
  <table
    border="0"
    cellpadding="0"
    cellspacing="0"
    class="table"
    style="border-collapse: collapse; margin: 0 auto"
  >
    <tbody>
      <tr style="background-color: #eee">
        <th>名称</th>
        <th>属性</th>
        <th>价格</th>
        <th>数量</th>
        <th>小计</th>
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
    </tbody>
  </table>
</div>
<!-- 引入JS文件 -->
<script src="../jquery.jqprint-0.3.js?v=1.0" type="text/javascript"></script>
<script
  src="../jquery-migrate-1.2.1.min.js?v=1.0"
  type="text/javascript"
></script>
<script>
    // 按钮点击打印
  function dayin() {
      // id是包裹的div的ID
    $("#dayinbufen").jqprint();
  }
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值