首页 > 代码库 > webform JS打印方法

webform JS打印方法

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DaYin.aspx.cs" Inherits="DaYin" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
   
<script language="Javascript">
    function preview() {
        bdhtml = window.document.body.innerHTML;
        sprnstr = "<!--startprint-->";   //指定内容
        eprnstr = "<!--endprint-->";     //指定内容
        prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
        prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
        window.document.body.innerHTML = prnhtml;
        window.print();
    }
</script>

    <body>

              <!--省略部分代码-->
    <form id="WebForm1" method="post" runat="server">
    <div>
       
    <%-- -----------------------<center>本部分以上不被打印</center>-------------------------------%>
     <!--startprint-->
     <div align="center">    <%--绑定要打印的内容--%>
         <h2>用户详情</h2>
         <table border="1" cellspacing="0">
    <tr align="center">
        <td><input type="checkbox" name="checkId" value="" id="checkAll">序号</td>
        <td>姓名</td>
        <td>性别</td>
        <td>籍贯</td>
        <td>民族</td>
        <td>身份证</td>
        <td>出生日期</td>
        <td>文化程度</td>
        <td>政治面貌</td>
        <td>婚否</td>
        <td>固定电话</td>
        <td>移动电话</td>
        <td>所属小区</td>
        <td>楼号</td>
        <td>门牌号</td>
        <td>所属网格</td>
        <td>退伍军人</td>
        <td>迁入时间</td>
    </tr>
    <!--循环开始之地-->
    <tr align="center" data_id="1">
        <td rowspan="6"><input type="checkbox" class="checked" name="checkId" value="" id="checkId-">1</td>
        <td>刘</td>
        <td>男</td>
        <td>淄博</td>
        <td>汉族</td>
        <td>3703。。。</td>
        <td>1995.01.08</td>
        <td>大专</td>
        <td>团员</td>
        <td>未婚</td>
        <td>3199611</td>
        <td>152。。。。</td>
        <td>王社区</td>
        <td>13</td>
        <td>502</td>
        <td>第一网格</td>
        <td></td>
        <td>2016.11.26</td>
        
    <tr class="detail" data_id="1">
        <td colspan="3">户籍地:淄博市</tdcolspan>
        <td colspan="3">户籍登记地址:山</td>
        <td colspan="2">出生地:高</td>
        <td colspan="3">户籍地县级公安机关:高</tdcolspan>
        <td colspan="3">户籍地派出所:</td>
        <td colspan="3">工作单位;山</td>      
    </tr>
    <tr class="detail" data_id="1">
        <td colspan="14">属性标签:</td>
        <td colspan="4">社团:</td>
    </tr>
    <tr class="detail" data_id="1">
        <td colspan="3">产权人:孙悟空</td>
        <td colspan="15">居住人:刘</td>
    </tr>   
    <tr class="detail" data_id="1"></tr>
    <!--循环结束之时-->
</table>

     </div>

     <!--endprint-->
    <%-- ------------------------<center>本部分以下不被打印</center>------------------------  --%>

     <div align="center">
         <input type="button" name="print" value="http://www.mamicode.com/预览并打印" onclick="preview()">
     </div>

    </div>
    </form>
</body>
</html>

 

 

 

 

    

webform JS打印方法