当前位置:首页 > 开发 > 编程语言 > 编程 > 正文

js 调用打印

发表于: 2015-03-05   作者:cuityang   来源:转载   浏览:
js
摘要: js打印代码: var bdhtml=document.getElementById("content1").innerHTML; window.document.body.innerHTML=bdhtml; window.print(); <!-- 打印内容在这里 --> <div id="printWnd" style
js打印代码:
var bdhtml=document.getElementById("content1").innerHTML;
window.document.body.innerHTML=bdhtml;
window.print();


<!-- 打印内容在这里 -->
<div id="printWnd" style="display:none;">
<label>姓名:</label><label id="p_userName"></label><br>
<label>身份证号:</label><label id="p_idCard"></label><br>
<label>科目名称:</label><label id="p_subjectName"></label><br>
<label>电话号码:</label><label id="p_telPhone"></label><br><br>
<label>补考费金额:</label><label id="p_extraFee"></label><br>
<label>补考费原因:</label><label id="p_remark"></label><br>
</div>

  var text = $("#printWnd")[0].innerHTML;
printView(text); //打印预览

//打印预览
function printView(obj){
var oWin=window.open("","_blank");   
var strPrint="<h4 style=’font-size:18px; text-align:center;’>补考费-打印预览</h4>\n";   
 
strPrint=strPrint +"<script type=\"text/javascript\">\n";   

strPrint=strPrint + "function printWin()\n";
strPrint=strPrint + "{"; 
strPrint=strPrint +    "var bdhtml=document.getElementById(\"content1\").innerHTML;\n";
strPrint=strPrint +    "window.document.body.innerHTML=bdhtml;  \n";
strPrint=strPrint +    "window.print();  \n";
strPrint=strPrint + "}"; 
    strPrint=strPrint + "<\/script>\n";   
        
 
    strPrint=strPrint + "<div id=\"content1\" >\n";   
    strPrint=strPrint + obj + "\n";   
    strPrint=strPrint + "</div>\n";   
 
    strPrint=strPrint + "<hr size='1'/>\n";   
    strPrint=strPrint + "<div style='text-align:center'><button onclick='printWin();' style='padding-left:4px;padding-right:4px;'>打  印</button><button onclick='window.close();'  style='padding-left:4px;padding-right:4px;'>关  闭</button></div>\n";   
 
    oWin.document.write(strPrint);   
    oWin.focus();   
 
    oWin.document.close();   

js 调用打印

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号