Javascript jQuery printelement函数在浏览器中不工作
我正在使用printelement jQuery。在stackoverflow和其他许多搜索资源的方法中找到了一些解决方案,但仍然不起作用Javascript jQuery printelement函数在浏览器中不工作,javascript,jquery,Javascript,Jquery,我正在使用printelement jQuery。在stackoverflow和其他许多搜索资源的方法中找到了一些解决方案,但仍然不起作用 <script type="text/javascript"> function PrintElem(elem) { Popup($(elem).html()); } function Popup(data) { var mywindow = window.open('', 'PRINT', 'height=400,width=
<script type="text/javascript">
function PrintElem(elem)
{
Popup($(elem).html());
}
function Popup(data)
{
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head><title></title>');
mywindow.document.write('<link rel="stylesheet" href="assets/css/neon-theme.css" type="text/css" />');
mywindow.document.write('<link rel="stylesheet" href="assets/js/datatables/responsive/css/datatables.responsive.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(“”,'PRINT','height=400,width=600');
mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(数据);
mywindow.document.write(“”);
mywindow.print();
mywindow.close();
返回true;
}
没错。使用jquery html,比如so$('#divelement').html(yourehtmlcode)
从类似的线程中考虑这个答案
代码如下所示:
var divToPrint=document.getElementById('DivIdToPrint');
var newWin=window.open('','Print-Window');
newWin.document.open();
newWin.document.write('<html><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');
newWin.document.close();
setTimeout(function(){newWin.close();},10);
var divToPrint=document.getElementById('DivIdToPrint');
var newWin=window.open(“”,'Print-window');
newWin.document.open();
newWin.document.write(“”+divToPrint.innerHTML+“”);
newWin.document.close();
setTimeout(函数(){newWin.close();},10);
我认为您的css链接有问题,请尝试一下:
函数PrintElem(elem)
{
弹出($(elem.html());
}
功能弹出窗口(数据)
{
var myWindow=window.open(“”,'PRINT','height=400,width=600');
myWindow.document.write(“”);
myWindow.document.write(“”);
myWindow.document.write(数据);
myWindow.document.write(“”);
myWindow.print();
myWindow.close();
返回true;
}
有什么问题?打印空白页。标题有误导性。您没有使用jquery,而是使用纯Javascript。这将更改元素。这对这个问题有什么帮助?哦,我以为这就是问题所在,没关系。下次仔细阅读问题。我建议你在有人投票否决你之前删除这个答案:)对这个问题没有帮助。我会尝试一下css缺少的东西。它需要内部css。试试看,我希望问题解决了。然后我怀疑还有其他问题。它对我有用。你得到了什么?以前,每当用户打印它生成的带有头标签的webpartextension=“full”数据时,我都会使用html打印,它会抛出错误(不是打印)newWin.document.write(“”+divToPrint.innerHTML+“”);