window.print打印3份

时间:2019-12-09 19:35:55

标签: javascript printing

我要疯了,请帮助我。

我只需要使用window.print命令打印票证...但无需说明打印机将打印票证的三份副本。

这是我的代码:

    function printTicket(number){
        document.getElementById("num2").innerHTML = number;
        $('#MyModal').modal('show');
        setTimeout(function () {
               printElement(document.getElementById("printThis"));
        }, 500);

    $('#MyModal').modal('hide');    
    return true;
}


function printElement(elem) {
    var domClone = elem.cloneNode(true);

    var $printSection = document.getElementById("printSection");

    if (!$printSection) {
        var $printSection = document.createElement("div");
        $printSection.id = "printSection";
        document.body.appendChild($printSection);
    }

    $printSection.innerHTML = "";
    $printSection.appendChild(domClone);
    window.print();
}

正确设置了打印机设置以打印一份副本

这是要打印的模式对话框

<div id="printThis">
<div id="MyModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">

  <div class="modal-dialog modal-sm">

    <!-- Modal Content: begins -->
    <div class="modal-content">


      <!-- Modal Body -->  
      <div class="modal-body">
        <div class="body-message">
          <table id="Table_02" width="170" height="283" border="0" cellpadding="0" cellspacing="0">
          <tr><td><img src="img/images/numeretto_new_01.jpg" width="170" height="169" alt=""></td></tr>
          <tr><td><div style="font-size:100px; text-align:center" id="num2"></div></td></tr>
          <tr><td><img src="img/images/numeretto_new_03.jpg" width="170" height="37" alt=""></td></tr>
          </table>
        </div>
      </div>



    </div>
    <!-- Modal Content: ends -->

  </div>
 </div>
</div>

当最后一个表单的字段失去焦点时,操作开始

 <input type="text" name="nome" id="nome" value="" autocomplete="off"  class="formTS" style="top:235px; left:-57px" onChange="insertCue()">

函数insertCue()通过ajax调用PHP,并返回要打印的数字

function insertCue() {

    var userName = document.getElementById('name').value;
    var userSurname = document.getElementById('surname').value;
    var userCF = document.getElementById('cf').value;



     var xmlhttp = new XMLHttpRequest();    

        xmlhttp.onreadystatechange = function() {

            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    printTicket(xmlhttp.responseText);

                 }

             }
        xmlhttp.open("GET", "insertCue.php?userName="+userName+"&userSurname="+userSurname+"&userCF="+userCF, true);
        xmlhttp.send();



}

0 个答案:

没有答案