如何将整个 div 复制到弹出窗口?
我正在尝试做的事情:
function ImprimirTela() {
var text = "<html>\n<head>\n<title>Impressão Guia</title>\n";
text += "<script src='~/js/jquery-1.4.2.js' type='text/javascript' language='javascript' />\n";
text += "</head>\n<body>\n";
text += "<input type='button' value='Imprimir esta página' onclick='window.print();' style='float: right' />\n";
text += "<div id='conteudo'>\n";
text += $("#divDadosBasicos").html($(querySelector).html());
text += $("#divHipotesesDiagnosticas").html($(querySelector).html());
text += "</div>\n/body>\n</html>";
var newWindow = window.open('', 'Impressao', 'width=900,height=700');
newWindow.document.write(text);
}
我不知道这是否是更好的方法。如果您认为/知道更简单的方法,请分享
提前致谢!
最佳答案
修复其中一些错误,它将正常工作
- 脚本标签未正确关闭
- body 标签未正确关闭
querySelector 未定义。 (我正在评论那部分)
function ImprimirTela() { var text = "<html>\n<head>\n<title>Impressão Guia</title>\n"; text += "<script src='~/js/jquery-1.4.2.js' type='text/javascript' language='javascript'></script>\n"; text += "</head>\n<body>\n"; text += "<input type='button' value='Imprimir esta página' onclick='window.print();' style='float: right' />\n"; text += "<div id='conteudo'>\n"; //define querySelector //text += $("#divDadosBasicos").html($(querySelector).html()); //text += $("#divHipotesesDiagnosticas").html($(querySelector).html()); text += "</div>\n</body>\n</html>"; var newWindow = window.open('', 'Impressao', 'width=900,height=700'); newWindow.document.write(text); }
关于javascript - 将 div 复制到弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9672738/