我正在尝试使用jquery函数打印一个表,但是点击“打印”#39;按钮我只有空页。数据无法加载到页面。
我的代码
<script>
function print_click(divname)
{
var printcontents = document.getElementById(divname).innerHTML;
var originalcontents = document.body.innerHTML;
document.body.innerHTML = printcontents;
window.print();
document.body.innerHTML = originalcontents;
}
<div runat="server" id="studentlist">
<asp:Label id="statuslabel" runat="server"></asp:Label>
<table style="margin-top:100px;margin-left:35px">
<tr style="height:20px;padding-left:30px;">
<th runat="server" id="regno" style="color:white">REG NO</th>
<th runat="server" id="studname" style="color:white">STUDENT NAME</th>
<th runat="server" id="dept" style="color:white">DEPARTMENT</th>
<th runat="server" id="degre" style="color:white">CGPA</th>
<th runat="server" id="twlth" style="color:white">%IN XII</th>
<th runat="server" id="cnum" style="color:white">CONTACT NO</th>
</tr>
<asp:ListView runat="server" ID="ListView1" OnItemCommand="ListView1_ItemCommand">
<itemtemplate>
<tr style="margin-left:100px">
<td style="width:120px;">
<asp:Label ID="Label5" runat="server" Text='<%# Eval("reg_no") %>' /></td>
<td style="width:120px;padding-right:0px">
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("student_name") %>' /></td>
<td style="width:120px">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("department_name") %>' /></td>
<td style="width:120px">
<asp:Image ID="Image1" style="height:130px;width:120px;" runat="server" ImageUrl='<%#Eval("image_name")%>'/></td>
<td>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="dwnload" Text="Download Image">
</asp:LinkButton>
</td>
</tr>
</itemtemplate>
</asp:ListView>
</table>
</div>
<input runat="server" type="button" name="Print" value="print" class="mybtn" id="prntbtn" onclick="print_click('studentlist')"/>
我有一个html按钮和&#34; onclick&#34;按钮单击工作正常,但打印页面没有数据。