欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js实现页面打印部分内容功能

程序员文章站 2022-03-04 15:53:03
...
<div class="scanCodeDiv" id="forPrint">
      <img src="../../../assets/image/scanCodeDivBg.png">

      <div class="scanCodeDivDes">
        <h2>请下载车企智链APP</h2>
        <h2>扫码接单</h2>
        <div class="scanCodeBg">
          <img src="../../../assets/image/scanCodeBg.png">
          <div class="qrcode" ref="qrCodeUrl"></div>
        </div>
        <h2 style="font-size: 20px;">煤炭</h2>
        <h2 style="font-size: 16px;">目的地</h2>
        <div class="scanCodeAddress">
          <div style="float: left;margin-top: 14px"><img src="../../../assets/image/redstar.png"></div>
          <div class="scanCodeTxt">
            <p>陕西省西安市未央区地铁2号线行政中心地铁B口向西300米</p>
            <p>运输距离500.22km</p>
          </div>
        </div>
      </div>
    </div>
      //打印
      goToPrinting(){
        var printData=document.getElementById("forPrint").innerHTML;
        window.document.body.innerHTML=printData;
        window.document.close();
        window.print();
        window.location.reload();
      },
 .scanCodeDiv {
      float: left;
      width: 595px;
      height: 808px;
    }
 
    .qrcode{
      position: absolute;
      left: 192px;
      top: 56px;
    }
    .scanCodeBg {
      position: relative;
    }

    .scanCodeDiv h2 {
      font-size: 28px;
      font-weight: bold;
      color: #333333;
    }

    .scanCodeTxt {
      float: left;
      margin-left: 14px;
      text-align: left;
    }
    .scanCodeTxt p {
      font-size: 14px;
      color: #333333;
    }
    .scanCodeDivDes {
      position: absolute;
      top: 110px;
      width: 595px;
      text-align: center;
    }
    .scanCodeAddress {
      padding: 0 102px;
    }

备注:制作页面打印有背景图片时,一定用<img>标签,这样打印上有图片,如果用background定义图片,打印出来看不到背景图片

相关标签: javascript jquery