【问题标题】:How to print HTML div in Chrome browser using JQuery如何使用 JQuery 在 Chrome 浏览器中打印 HTML div
【发布时间】:2014-08-08 06:45:48
【问题描述】:

我必须使用 JQuery 在 Chrome 浏览器中打印 HTML din 及其内部 HTML。我尝试使用“printWindow.print()”函数,但它不起作用。我在页面上还有另一个按钮,所以在使用上述功能时,它会进入死锁状态,另一个按钮的点击事件不起作用。请提出一些可行的建议。

谢谢。

【问题讨论】:

  • 您能否发布您的 HTML 和脚本代码,以便我们了解您要执行的操作?
  • 你的意思是,你想打印出特定<div>中的内容,还是别的什么?
  • $(document).ready(function () { $("#btnContinue").click(function () { $("#btnPrint").click(function () { PrintDocuments($ ('#DivId').html()); }); function PrintDocuments(divContents) { var printWindow = window.open('', '_blank', 'height=400,width=800,,location=no') ; printWindow.document.write(divContents); printWindow.document.close(); printWindow.print(); return false; } });

标签: jquery google-chrome printing


【解决方案1】:

根据您的问题,我认为您看起来像这样。

HTML:

<div id="ID1">Test Div</div>
<br/>
<input type="button" value="copy from ID1" id="btn" />
<br/><br/>
<div id="outputdiv"></div>

JS:

$(document).ready(function () {
 $("#btn").click(function () {
  $("#outputdiv").html($("#ID1").html());
 });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    • 2017-01-28
    • 2018-05-13
    • 1970-01-01
    • 2015-11-11
    相关资源
    最近更新 更多