这是jquery
代码::
<script type="text/javascript">
function PrintElem(elem) {
Popup($(elem).html());
}
function Popup(data) {
alert(document.getElementById('<%=imgphoto.ClientID%>').src);
var mywindow = window.open('', 'Customer Details', 'height=400,width=600');
mywindow.document.write('<html><head><title>Customer Details</title>');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.print();
mywindow.close();
return true;
}
</script>
这是我的源代码::
<div id="mydiv">
<table style="width: 100%">
<tr>
<td colspan="2" style="font-size: large">
Customer Document Details
</td>
</tr>
<tr>
<td colspan="2">
<b></b>
</td>
</tr>
<tr>
<td style="height: 20px; width: 140px">
<b>Photo</b>
</td>
<td style="font-weight: 700">
<asp:Image ID="imgphoto" runat="server" AlternateText="Image Not Available" class="imgresize"
ForeColor="Red" Height="85px" ImageUrl="~/Images/Empty.png" Width="109px" />
</td>
</tr>
</table>
</div>
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="PrintElem('#mydiv')"
CausesValidation="False" />
我的问题::
我正在尝试在按钮div tag
上打印OnClientClick="PrintElem('#mydiv')"
的所有内容,但我获取除了Image之外的div标签的所有内容。所以请在打印页面时帮助我获取图像控制。< / p>
答案 0 :(得分:0)
我修改了你的代码
<强>脚本强>
<script type="text/javascript">
function PrintElem(elem) {
Popup($(elem).html());
}
function Popup(data) {
alert(document.getElementById('<%=imgphoto.ClientID%>').src);
var mywindow = window.open('', 'Customer Details', 'height=400,width=600');
mywindow.document.write(data);
mywindow.print();
mywindow.close();
return true;
}
</script>
源代码:
<div id="mydiv">
<table style="width: 100%">
<tr>
<td colspan="2" style="font-size: large">
Customer Document Details
</td>
</tr>
<tr>
<td colspan="2">
<b></b>
</td>
</tr>
<tr>
<td style="height: 20px; width: 140px">
<b>Photo</b>
</td>
<td style="font-weight: 700">
<asp:Image ID="imgphoto" runat="server" AlternateText="Image Not Available" class="imgresize"
ForeColor="Red" Height="85px" ImageUrl="Desert.jpg" Width="109px" />
</td>
</tr>
</table>
</div>
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="PrintElem('#mydiv')"
CausesValidation="False" />
完美地工作。
我上面的代码没有用。请参考以下网址中的另一个 http://www.aspdotnet-suresh.com/2013/08/jquery-print-div-content-with-css-using.html” 它也在工作