zoukankan      html  css  js  c++  java
  • 打印表格

    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%;100%"  修饰表格

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

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

    美好生活
  • 相关阅读:
    Java Collection知识总结
    Java异常总结
    关于触发器
    关于事务
    git分支的创建、删除、切换、合并
    github项目上传管理
    如何在github上下载单个文件夹?
    常见的javascript跨站
    各类常用端口漏洞缺陷
    SEO优化实践操作
  • 原文地址:https://www.cnblogs.com/ssbydk/p/9541351.html
Copyright © 2011-2022 走看看