如何使用jQuery打印文档中的表内容
How to Print Table Content in Document Using jQuery?
如何使用jQuery只打印文档的表?
<!--panel-->
<div class="panel panel-primary">
<!-- Default panel contents -->
<div class="panel-heading">New Order
<button class="btn btn-sm pull-right btn-default" type="submit">Print Item</button>
</div>
<div class="panel-body">
<!--table-->
<table class="table table-condensed">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<td>2</td>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<td>3</td>
<td colspan="2">Larry the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
<!--end of table-->
</div>
</div>
<!--end of panel-->
演示
您可以试试这个函数。将您的表放在具有唯一ID的div中,然后在JQuery:中引用它
<script>function printDiv() {
var divName= "<DIV ID HERE>";
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}</script>
试试这个(演示):
$(function () {
$('button[type="submit"]').click(function () {
var pageTitle = 'Page Title',
stylesheet = '//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css',
win = window.open('', 'Print', 'width=500,height=300');
win.document.write('<html><head><title>' + pageTitle + '</title>' +
'<link rel="stylesheet" href="' + stylesheet + '">' +
'</head><body>' + $('.table')[0].outerHTML + '</body></html>');
win.document.close();
win.print();
win.close();
return false;
});
});
相关文章:
- 如何在外部文档中使用javascript将文本区域的内容保存为变量
- 在HTML文档中使用XML文件中的数据
- 如何在更新mongo文档时使用变量
- Sharepoint文档库-使用javascript从文件名到标题
- 我可以在 html 文档中使用 if/else if 命令吗?
- XPath 出错.节点不能在创建节点的文档以外的文档中使用
- 我的文档何时使用猫鼬保存功能保存
- 在 HTML 文档之外使用 Jquery 的 append()
- 需要使用此JSON文档并使用$.ajax()从API创建每小时一次的天气更新
- 在文档之间使用jQuery的Javascript不起作用
- 我可以在文档上使用什么来不时应用函数,包括未来元素
- 在一个文档中使用两次javascript文档就绪
- 如何在一个文档中使用两个id.getElementById类型函数
- 从外部文件返回一个JavaScript变量到HTML文档,然后在HTML文档中使用它
- 范围是怎样的?在HTML文档中使用多个Javascript脚本标签
- 在同一文档中使用Javascript中的PHP变量
- 什么是最好的方法来计算字符数在html dom节点(在文档节点使用javascript范围库)
- 如何在xsl文档中使用javascript函数
- 我应该把变量在窗口.文档或使用全局上下文
- 为什么getElementsByName只能在JavaScript文档中使用?