我想打印一个特定的表格数据元素。
表结构如下。
| Table No | Table Code | Description | Action |
     4           8785        abc         Print
     5           7463        cde         Print
     6           5645        fgh         Print
当我单击“打印”链接时,我想打印一行的前两列(表号、表代码)的元素。
下面的 javascript 代码打印整行。
<script type="text/javascript">
    function Print(a) {
        alert("heloo");
        var row = $(a).closest("tr").clone(true);
        var printWin = window.open('', '', 'left=0", ",top=0,width=1000,height=600,status=0');
        var table = $("[id*=tableCodeTable]").clone(true);
        $("tr", table).not($("tr:first-child", table)).remove();
        table.append(row);
        $("tr td:last,tr th:last", table).remove();
        var dv = $("<div />");
        dv.append(table);
        printWin.document.write(dv.html());
        printWin.document.close();
        printWin.focus();
        printWin.print();
        printWin.close();
    }
</script>  
打印链接的html代码
<a href="javascript:;" onclick="Print(this)">Print</a>
表格的html代码
<table border="2px" id="tableCodeTable" class="table">
  <tr>
        <th>
            Table No
        </th>
        <th>
            Table Code
        </th>
        <th>
            Description
        </th>         
        <th>
            Action
        </th>
    </tr>
    <tbody>
 <% foreach (var item in Model.Mapping)
 {%>   
   <tr id="<%=item.Id%>">
        <td id="no_<%=item.Id%>" class="two">
             <input type="hidden" value=" <%=item.Id%>"/>
            <%=item.TableNo%>
        </td>
        <td>
            <%=item.TableCode%>
        </td>
      <td id="dc_<%=item.Id%>" class="twoo"> 
           <%=item.Description%>
       </td>          
        <td>      
             <a href="javascript:;" onclick="Print(this)">Print</a>
        </td>
  </tr>            
 <% } %>
 </tbody>   
</table>
我怎样才能只打印这两个元素?请帮忙。