我有这个javascript代码从PHP文档打印html表。
function printReport()
{
var data = '<input type="button" value="Print this page" onClick="window.print()">';
data += '<input type="button" value="Close this page" onClick="window.close()">';
data += '<table border="0"';
data += $('#reportTable').html();
data += '</table>';
myWindow=window.open('','','scrollbars=yes,resizable=yes,width=500,height=400');
myWindow.innerWidth = screen.width;
myWindow.innerHeight = screen.height;
myWindow.screenX = 0;
myWindow.screenY = 0;
myWindow.document.write(data);
myWindow.focus();
};
它打开新窗口,显示内容,关闭按钮工作正常,但打印按钮不起作用。
我的打印机工作正常,我从word或任何其他应用程序打印出来并且工作正常。
我的问题是:打印功能window.print()
无效。
如果有人能帮助我,我将不胜感激。
干杯
答案 0 :(得分:0)
变化:
data += '<table border="0"';
到
data += '<table border="0">';
告诉我们最终结果。在表格中使用简单的HTML内容进行测试。假设您的.html()
调用返回有效的表数据,则该窗口现在应该可以打印。
在这里工作小提琴:http://jsfiddle.net/aV85r/