我在打印div内容时遇到问题。正确打印它显示错误,如'sys'undefined ..可以任何人告诉我解决方案,
<div id="mydiv" runat="server" style="display:none;">
</div>
我的javascript是:
function Print() {
var PrintDiv = $('#' + '<%= mydiv.ClientID %>').html();
//var NewWindow = window.open('', '', 'width=500,height=500');
var NewWindow = window.open('', '_blank', 'location=1,status=1,scrollbars=1,width=1000,height=700');
NewWindow.document.open("text/html");
NewWindow.document.write('<html><head><title></title>');
NewWindow.document.write('<link href="CSS/style.css" rel="stylesheet" type="text/css" />');
NewWindow.document.write('</head><body onload="window.print()">');
NewWindow.document.write(PrintDiv);
NewWindow.document.write('</body></html>');
NewWindow.document.close();
}
答案 0 :(得分:0)
您好打印div我正在做以下事情,希望您能找到解决方案
function printdiv(strid, rptName) {
var prtContent = document.getElementById(strid);
// Intial header
var html = '<html>\n<head>\n';
html += '<title>' + 'Name of your project : ' + rptName + '</title>';
// Get value for header for Telerik stylesheet
if (document.getElementsByTagName != null) {
var headTags = document.getElementsByTagName("head");
if (headTags.length > 0)
html += headTags[0].innerHTML;
}
html += ' <title>' + 'Name of your project-' + rptName + ' </title>';
// End the header and open body
html += '\n</head>\n<body>\n';
if (prtContent != null) { // Get all html
html += document.getElementById(strid).innerHTML;
}
else {
alert("Could not find the print div");
return;
}
//End the body and html
html += "\n</body></html>";
// Opem new wind
var WinPrint = window.open('', '', 'letf=10,top=10,width="450",height="250",toolbar=1,scrollbars=1,status=0');
WinPrint.document.write(html);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
return false;
}
答案 1 :(得分:0)
我认为只有一个陈述会改变你的代码,
var PrintDiv = $('#' + '<%= mydiv.ClientID %>').innerHtml();
如果您将HTML称为div样式&gt;&gt;显示无人正在呼叫,
检查代码
alert(PrintDiv);
如果这是返回值,则会打印。
我希望这会有所帮助:)