Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将div复制到弹出窗口_Javascript_Jquery_Popup_Copy - Fatal编程技术网

Javascript 将div复制到弹出窗口

Javascript 将div复制到弹出窗口,javascript,jquery,popup,copy,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

如何将整个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);
    }
函数不正确(){
var text=“\n\nImpressão Guia\n”;
text+=“\n”;
text+=“\n\n”;
text+=“\n”;
text+=“\n”;
text+=$(“#divDadosBasicos”).html($(querySelector.html());
text+=$(“#divhipotesesdiagnostics”).html($(querySelector.html());
text+=“\n/body>\n”;
var newWindow=window.open(“”,'Impressao','width=900,height=700');
newWindow.document.write(文本);
}
我不知道这是不是更好的方法。如果你认为/知道更简单的方法,请分享


提前谢谢

您可以使用Jquery模式弹出窗口

看看吧,它有你需要的功能


它有几个事件可以修改数据。

刚刚测试过,只要定义了
querySelector
,并且它在document.ready函数中,并且您正在实际的Web服务器(如WAMP/LAMP等)上测试,代码似乎工作得很好。它在JSFIDLE等地方不起作用。

修复其中一些错误,它会很好地工作

  • 脚本标记未正确关闭
  • 车身标签未正确关闭
  • 未定义查询选择器。(我正在评论这一部分)

    函数不正确(){
    var text=“\n\nImpressão Guia\n”;
    text+=“\n”;
    text+=“\n\n”;
    text+=“\n”;
    text+=“\n”;
    //定义查询选择器
    //text+=$(“#divDadosBasicos”).html($(querySelector.html());
    //text+=$(“#divhipotesesdiagnostics”).html($(querySelector.html());
    text+=“\n\n”;
    var newWindow=window.open(“”,'Impressao','width=900,height=700');
    newWindow.document.write(文本);
    }
    

  • 你在哪里尝试这个,JSFIDLE?不,VisualStudio(asp.Net+C#+Javascript)。为什么正文和脚本标记没有正确关闭?您能告诉我如何修复吗?请检查您的代码'text+=“\n/body>\n”`您必须始终关闭脚本标记,如
    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);
    }