网络代码如下
<asp:Image runat="server" ID="img1" ImageUrl="~/Images/important.gif" />
<asp:Button ID="btn" runat="server" Text="print" />
我的javascript如下
<script type="text/javascript">
function printIt() {
var win = window.open('', 'Image', 'resizable=yes,...');
if (win) {
//var imgID = '<%= img1.ClientID %>';
var imageControl = document.getElementById('<%=img1.ClientID%>').src;
win.document.write(imageControl);
win.document.close();
win.focus();
win.print();
}
return false;
}
</script>
//根据vitoshabg
回复更新代码
<script type="text/javascript">
function printIt() {
var win = window.open('', 'Image', 'resizable=yes,...');
if (win) {
//var imgID = '<%= img1.ClientID %>';
var imageControl = document.getElementById('<%=img1.ClientID%>').src;
win.write('<img src="' + imageControl + '">');
//win.write(imgParent);
win.document.close();
win.focus();
win.print();
}
return false;
}
</script>
但是我得到的网址可以帮助我获取图片
,而不是图片答案 0 :(得分:1)
var imageControl = document.getElementById('<%=img1.ClientID%>').src;
这里你得到了getElementById返回的元素的'src'属性。
您可以使用
创建新图像 win.document.write('<img src="' + imageControl + '">');
答案 1 :(得分:0)
您收到的网址是因为此行末尾有.src
:
var imageControl = document.getElementById('<%=img1.ClientID%>').src;
将其更改为此以获得图像控制:
var imageControl = document.getElementById('<%=img1.ClientID%>');
答案 2 :(得分:0)
删除了Bug;)
<script type="text/javascript">
function printIt() {
var win = window.open('', 'Image', 'resizable=yes,...');
if (win) {
//var imgID = '<%= img1.ClientID %>';
var imageControl = document.getElementById('<%=img1.ClientID%>');
win.document.write(imageControl);
win.document.close();
win.focus();
win.print();
}
return false;
}
</script>