<button type="button" class="btn btn-info" οnclick="doPrint()">打印按钮</button>
<script>
        function doPrint() {
            // 0. 备份之前页面,因为后面页面有改动
            var bdhtml = window.document.body.innerHTML;
            var html = "";
            // 1. 根据选择条件获取数据            
            var matchId = $("#match").val();// 赛事
            var campusId = $("#matchTeam").val();// 校区
            $.ajax({
                type : "GET",
                async : false,
                url : "/generPrintData?matchId="+matchId+"&campusId="+campusId,
                error : function(request) {
                    parent.layer.alert("Connection error");
                },
                success : function(data) {
					// 2. 根据取得数据渲染 div
                    for (var i=0;i<data.length;i++){
                        var obj = data[i];
                        var showHtml = "";
                        showHtml = "<div id=\"printDiv\" style=\"width: 210mm;page-break-after: always\">";
 
			showHtml += "<div style=\"text-align:center;height: 10mm;margin-top: 30mm;font-family: 宋体;font-weight:bold;font-size: 30px\">"+obj.matchName+"</div><br>";
			showHtml += "<div style=\"text-align:center;height: 60mm\">";
			showHtml += "<table style=\"width: 150mm;text-align: left;margin-left: 20mm;font-size: 20px;font-family: 宋体\">";
			showHtml += "<tr style=\"height: 8mm\"><td width=\"400mm\">姓  名:"+obj.name+"</td><td>性别:"+obj.sex+"</td></tr>";
			showHtml += "<tr style=\"height: 8mm\"><td>报考单位:"+obj.campusName+"</td></tr>";
			showHtml += "<tr style=\"height: 8mm\"><td>出生日期:"+obj.birthday.split(" ")[0]+"</td></tr>";
			showHtml += "<tr style=\"height: 8mm\"><td>考试级别:"+obj.levelName+"</td></tr>";
			showHtml += "<tr style=\"height: 8mm\"><td>考试带色:"+obj.beltColor+"</td></tr>";
                        showHtml += "<tr style=\"height: 8mm\"><td>指导教练:"+obj.coach+"</td></tr>";
                        showHtml += "<tr style=\"height: 8mm\"><td>考试编号:"+obj.matchAddress+obj.stage+obj.stageOrder+"</td></tr>";
                        showHtml += "</table>";
                        showHtml += "</div><br><br>";
                        showHtml += "<div style=\"margin-left: 55mm;font-family: 宋体;font-size: 18px\">备 注</div><br>";
                        showHtml += "<div style=\"text-align: left;font-family: 宋体;margin-left: 20mm;font-size: 18px\">1.学员凭此证进入考场参加晋级考试;</div>";
                        showHtml += "<div style=\"text-align: left;font-family: 宋体;margin-left: 20mm;font-size: 18px\">2.学院考级结束后凭准考证和成绩单领取证书和腰带;</div>";
                        showHtml += "</div>";
                        html += showHtml;
					}
                }
            });
 
            // 3. 打印该 div
            window.document.body.innerHTML = html;
            window.print();
            // 4. 还原备份页面
            window.document.body.innerHTML = bdhtml;
            window.location.reload();
        }
</script>
更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

Jalen Chu 微信支付

微信支付

Jalen Chu 支付宝

支付宝

Jalen Chu 公众号

公众号