【问题标题】:Is there a way to make a button print content from page and then submit(post) to backend JS?有没有办法让按钮从页面打印内容然后提交(发布)到后端 JS?
【发布时间】:2020-01-17 11:07:10
【问题描述】:

我需要先从页面打印内容,然后提交以使用表单帖子中的内容执行一些支持的数据库更改,有没有一种方法可以使用单个按钮来完成?

我已尝试将打印放入点击功能,但打印后不会发布

HTML:

<div class="printable" id="printableArea" style="display:block;">
    <div class="card" style="width: 500px;">
            ...
    </div>
</div>

<button id="printBtn" class="btn btn-lg btn-primary print-visibility-hide" onclick="printDiv('printableArea')" type="submit" value="SUBMIT">Print</button>

JS:

<script>
  function printDiv(divName) {
    var printContents = document.getElementById(divName).innerHTML;
    var originalContents = document.body.innerHTML;
    var count = $("#count").val();

    document.body.innerHTML = printContents;

    for(var i=1; i<count; i++){
        document.body.innerHTML += printContents;
    }

    window.print();

    document.body.innerHTML = originalContents;
  }

<script>

【问题讨论】:

    标签: javascript html node.js bootstrap-4


    【解决方案1】:
    window.onafterprint = function(){
       console.log("Printing completed...");
    }
    

    或者只是在window.print();之后添加

    setTimeout(() => { ...callback here }, 100);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多