jquery打印

jQuery打印表格、html页面

首先引入jquery.js 和jquery.jqprint.js

 <script src="jQuery-2.2.0.min.js"></script>
 <script src="jquery.jqprint.js"></script>

html内容

<div id="ddd">
	<table>
		<thead>
			<tr>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>1</td>
				<td>2</td>
				<td>3</td>
			</tr>
		</tbody>
		<tfoot>
		</tfoot>
	</table>
</div>
<input type="button" value="打印" onclick="print()">

js部分

function print(){
	$("#ddd").jqprint()
}

遇到 Cannot read property 'opera' of undefined错误问题是juqery版本兼容问题

解决方法:加入迁移辅助插件jquery-migrate-1.0.0.js可解决版本问题

<script src="http://www.jq22.com/jquery/jquery-migrate-1.2.1.min.js"></script>
原文地址:https://www.cnblogs.com/cwl1025/p/14754306.html