首页 > 其他 > 详细

打印表格

时间:2018-08-27 13:45:20      阅读:136      评论:0      收藏:0      [点我收藏+]

1、在jsp中与table 标签 同层次添加iframe标签

<iframe id=‘frmPrint‘  width=‘0‘ height=‘0‘ frameborder=‘0‘></iframe>
<table border="1" cellpadding="0" cellspacing="0" class="dateLisTable">
<thead style="background-color: #ebf5fc;">
</thead>
<tbody id="dataBody">
</tbody>
</table>

2、js中将表格数据写入到弹出框中

//打印功能
	document.getElementById("frmPrint").contentWindow.document.body.innerText = ""; //iframe清空后在复制防止多次写入重复
	 $(".dsdaochu01").attr("style","display:none;"); //隐藏打印导出按钮
	var initData = document.getElementsByClassName("page")[0].innerHTML
	var printData = document.getElementById("biao").innerHTML;// 获得
	var printWindow=window.frames[‘frmPrint‘];
	printWindow.document.write(printData);//内容写到iframe中去
	 $(".dsdaochu01").attr("style","display:true;"); 
	//document.getElementsByClassName(".dsdaochu01").style.display = "block"; // 显示
	
	layer.open({
		type : 1,
		title: false,
		fix : true,
		shadeClose : true,
		area : [ ‘100%‘, ‘100%‘ ],
		closeBtn : 0,
		content :‘<div >‘ + printData + ‘</div>‘,
		btn : [‘打印‘,‘关闭‘],
		yes : function(index) {
			printWindow.focus();
			window.print(); // 开始打印
		},
		
		success : function(layero) {
			$(‘.layui-layer-btn‘).position(‘relative‘);

			$(‘.layui-layer-btn‘)

		}
	});

3、打印不全问题

style="font-size:8px;height:100%;width:100%"  修饰表格

<table border="1" cellpadding="0" cellspacing="0" class="dateLisTable" style="font-size:10px;width:100%" >
</table>

通过宽度高度,字体大小调整

 

打印表格

原文:https://www.cnblogs.com/ssbydk/p/9541351.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!