Javascript 使用jquery打印插件打印div不会';行不通
我想使用此插件在我的代码中打印一个id为Javascript 使用jquery打印插件打印div不会';行不通,javascript,jquery,printing,jquery-plugins,Javascript,Jquery,Printing,Jquery Plugins,我想使用此插件在我的代码中打印一个id为AllTransactisaly的tbody,以解决打印时无法关闭/关闭模式的问题 这是我的密码 <div class="col-md-9"> <input type="hidden" name="clinic_idhid" id="clinic_idhid"> <div class="table_transactions" id="table_tra
AllTransactisaly
的tbody
,以解决打印时无法关闭/关闭模式的问题
这是我的密码
<div class="col-md-9">
<input type="hidden" name="clinic_idhid" id="clinic_idhid">
<div class="table_transactions" id="table_transactions">
<table id="mytransactions" class="table table-striped table-bordered table-hover dataTable dtr-inline" role="grid" style="width: 100%;" width="100%" aria-describedby="dataTables-material">
<thead>
<th>Check-up ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Check-up Date & Time</th>
<th>Bill Amount</th>
<tbody id="alltransactsdaily">
</tbody>
</table>
</div>
</div>
<button type="button" id="btn_printdiv" class="btn btn-primary"><span class="fa fa-print"></span> Print</button>
当我点击按钮时,控制台显示:
jquery.printElement.min.js:26 Uncaught TypeError: Cannot read property 'opera' of undefined
at jQuery.fn.init.a.fn.printElement (jquery.printElement.min.js:26)
at HTMLButtonElement.<anonymous> (Patients_report:392)
at HTMLButtonElement.dispatch (jquery-2.2.3.min.js:3)
at HTMLButtonElement.r.handle (jquery-2.2.3.min.js:3)
jquery.printElement.min.js:26未捕获类型错误:无法读取未定义的属性“opera”
位于jQuery.fn.init.a.fn.printElement(jQuery.printElement.min.js:26)
在HTMLButtoneElement。(病人报告:392)
在HTMLButtonElement.dispatch(jquery-2.2.3.min.js:3)
位于HTMLButtonElement.r.handle(jquery-2.2.3.min.js:3)
试试这个,它不会打开模式,它会在模式弹出窗口中打开同一页面上的打印
乱数假文
生长激素
函数printDiv(elementId){
var a=document.getElementById('printing-css')。值;
var b=document.getElementById(elementId).innerHTML;
window.frames[“print_frame”]。document.title=document.title;
window.frames[“print_frame”].document.body.innerHTML=''+a+''+b;
window.frames[“print_frame”].window.focus();
window.frames[“print_frame”].window.print();
}
您必须使用jQuery打印库,还是向其他库开放?@KevBot,谢谢您的回复。是的,我想使用jQuery插件来减少我在打印时的代码量,并且解决无法排除modalI意味着使用另一个外部库的问题。此库的工作方式如下PrintJob.print(“#alltransactisdayy”)
。它名为@KevBot,感谢您的回复,我遵循以下JSFIDLE:。为什么我的不行?有人回答吗?非常感谢您的回答,但我的情况是,在我的模态中有一个,而这个tbody在它里面,这就是我想要打印的内容。先生,你能改变你的答案吗。谢谢好的,我正在改变这个问题的答案,顺便问一下,这是什么?html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,首字母缩写,address,big,cite,code,del,df等。它用于格式化打印区域。如果您不需要任何特定元素,如按钮,则可以添加class=“no print”,以便打印区域将其删除。它还会打开一个示例页面,其中包含html,您正在将其推送到打印元素。
jquery.printElement.min.js:26 Uncaught TypeError: Cannot read property 'opera' of undefined
at jQuery.fn.init.a.fn.printElement (jquery.printElement.min.js:26)
at HTMLButtonElement.<anonymous> (Patients_report:392)
at HTMLButtonElement.dispatch (jquery-2.2.3.min.js:3)
at HTMLButtonElement.r.handle (jquery-2.2.3.min.js:3)
<div id="print-area-1" class="print-area">
<div style="text-align:right;"><a class="no-print" href="javascript:printDiv('print-area-1');">Print</a></div>
<h2>Lorem Ipsum</h2>
<p>gh.</p>
</div>
function printDiv(elementId) {
var a = document.getElementById('printing-css').value;
var b = document.getElementById(elementId).innerHTML;
window.frames["print_frame"].document.title = document.title;
window.frames["print_frame"].document.body.innerHTML = '<style>' + a + '</style>' + b;
window.frames["print_frame"].window.focus();
window.frames["print_frame"].window.print();
}