jsp浏览器打印表格

直接上代码,浏览器自带打印的功能。

<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2019/12/5
 Time: 0:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
 <head>
 <script>
  //直接在本窗口进行打印
  function windowprint() {

    var f = document.getElementById("printdiv");
    f.style.display = "";
    window.print();
    f.style.display = "none";
  }

  //新开一个窗口实现打印
  function myPrint(obj){

    var newWindow=window.open("打印窗口","_blank");
    var docStr = obj.innerHTML;
    newWindow.document.write(docStr);
    newWindow.document.close();
    newWindow.print();
    newWindow.close();
  }

	</script>
	<title>$Title$</title>
</head>
 <body>
 <a onclick="windowprint();" href="javascript:void(0);">点击打印</a>
 <div id="printdiv" style="display:none;">
  <table id="tableid" class="main" cellspacing="0" cellpadding="0" border="1"
           bordercolor="#000000" align="center" width="800px;">
	/******    这里写表格,或者其他任意的内容     ******/
	</table>
  </div>
 </body>
</html>

在这里插入图片描述

发布了101 篇原创文章 · 获赞 8 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_40764966/article/details/103396769