Javascript 打印div元素不';你不为我工作吗?
我有一个动态div类。div中的元素通过后端ajax web服务请求动态填充。:-Javascript 打印div元素不';你不为我工作吗?,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我有一个动态div类。div中的元素通过后端ajax web服务请求动态填充。:- <div class="hidden"> <asp:Button ID="Button1" runat="server" Height="23px" style="margin-top: 0px" Width="69px" text="Print" OnClientClick="PrintElem('#hidden'); return false;"/>
<div class="hidden">
<asp:Button ID="Button1" runat="server"
Height="23px" style="margin-top: 0px" Width="69px" text="Print" OnClientClick="PrintElem('#hidden'); return false;"/>
</div>
在这个div类中,动态填充的元素列表。
我试图使用这个div类中的print按钮来打印所有元素
function PrintElem(elem) {
Popup($(elem).html());
}
function Popup(data) {
var mywindow = window.open('', '.hidden', 'height=400,width=600');
mywindow.document.write('<html><head><title>Pharmacy List</title>');
/*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.print();
mywindow.close();
return true;
}
函数PrintElem(elem){
弹出($(elem.html());
}
功能弹出窗口(数据){
var mywindow=window.open('''.'隐藏','高度=400,宽度=600');
mywindow.document.write('药房列表');
/*可选样式表*///mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(数据);
mywindow.document.write(“”);
mywindow.print();
mywindow.close();
返回true;
}
*这对除IE之外的所有web浏览器都非常有效。*这是我用来打印DIV内容的代码,在IE中也可以正常工作
function printPartOfPage(elementId) {
var printContent = document.getElementById(elementId);
var windowUrl = 'Job Receipt';
var uniqueName = new Date();
var windowName = 'Print' + uniqueName.getTime();
var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');
printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
请尝试此代码这是我用来打印DIV内容的代码,它在IE中也可以正常工作
function printPartOfPage(elementId) {
var printContent = document.getElementById(elementId);
var windowUrl = 'Job Receipt';
var uniqueName = new Date();
var windowName = 'Print' + uniqueName.getTime();
var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');
printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
请尝试此代码尝试为窗口指定一个看起来像有效JavaScript标识符的名称(不同于“#隐藏”)。如何使用
获得class=“hidden”
?IE中有什么问题?你能用你的代码创建一个JSFIDLE吗?当我复制粘贴这段代码时,JSFIDLE不会为我创建按钮。但这正是我正在使用的代码。只需使用隐藏
而不是。隐藏
。您的代码与IE9+中的代码一样工作,但较旧的IEs不接受以字母开头的窗口名称。请尝试为窗口指定一个看起来像有效JavaScript标识符的名称(与“隐藏”不同)。如何使用获得class=“hidden”
?IE中有什么问题?你能用你的代码创建一个JSFIDLE吗?当我复制粘贴这段代码时,JSFIDLE不会为我创建按钮。但这正是我正在使用的代码。只需使用隐藏
而不是。隐藏
。您的代码与IE9+中的代码一样,但旧版IEs不接受以字母开头的窗口名。