javascript - 将 div 复制到弹出窗口

标签 javascript jquery popup copy

如何将整个 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);
    }

我不知道这是否是更好的方法。如果您认为/知道更简单的方法,请分享

提前致谢!

最佳答案

修复其中一些错误,它将正常工作

  1. 脚本标签未正确关闭
  2. body 标签未正确关闭
  3. 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/

相关文章:

javascript - HIGHCHARTS,将零替换为 0.1 >

javascript - 在 chrome 中打印 div,css 不起作用

javascript - 带有文本选择的 pdf.js

javascript - 检索对象自己的标签

javascript - NodeJS 使用 Puppeteer 处理弹出窗口

iphone - 在 iphone 中单击按钮时弹出 View 显示字符串

javascript - Javascript/Google Apps 脚本中二维数组的长度

JavaScript 重定向回引用页面

javascript - 获取给定前缀的完整类名

javascript - JQueryMobile 中的弹出窗口/工具提示位置