【问题标题】:submit data of form to a popup and print that popup window将表单数据提交到弹出窗口并打印该弹出窗口
【发布时间】:2014-06-23 18:17:19
【问题描述】:

我正在使用此代码从表单中获取提交的数据

<input id="name" name="name" type="text" class="auto-style8" style="width: 70%" />
<button id="singlebutton" name="singlebutton" class="btn btn-primary" onclick="return submit();">Submit</button> 
<div id="info"></div>
<script type="text/javascript">
    function submit()
    {
        var name = document.getElementById("name").value;
        document.getElementById("info").innerHTML = " My Name is "+name+" ";
    return false;
    }
</script>

结果显示在与表单相同的窗口中。 我想在弹出窗口中显示输出,并能够在主窗口中链接一个打印按钮,一旦单击该按钮将打印该弹出窗口的内容

edit: just to clarify more.

form submitted > open a new window > displays the entered results

谢谢

【问题讨论】:

标签: javascript html


【解决方案1】:

你可以这样修改你的代码:

<input id="name" name="name" type="text" class="auto-style8" style="width: 70%" />
<button id="singlebutton" name="singlebutton" class="btn btn-primary" onclick="return submit();">Submit</button> 
<div id="info"></div>
<script type="text/javascript">
    function submit()
    {
        var name = document.getElementById("name").value;
        document.getElementById("info").innerHTML = " My Name is "+name+" ";
        var r = window.confirm(" My Name is "+name+" .Click Ok To Print");
        if (r == true) {
            x = window.print();
        }
    return false;
    }
</script>

希望这能达到你的目的。

【讨论】:

  • 试试这个…… var myWindow = window.open("", "MsgWindow", "width=200, height=100"); myWindow.document.write("

    我的名字是 "+name+"

    ");
  • 我尝试了上一条评论中的解决方案,但对我来说,在 google-chrome 上 window.open 返回 undefined,这使得该解决方案不适用......
【解决方案2】:

我想你想要类似的东西

<input id="name" name="name" type="text" class="auto-style8" style="width: 70%" />
<button id="singlebutton" name="singlebutton" class="btn btn-primary" onclick="return submit();">Submit</button> 
<div id="info"></div>
<script type="text/javascript">
    function submit()
    {
        var name = document.getElementById("name").value;
        var output = " My Name is "+name+" ";
        var myWindow = window.open("data:text/html," + encodeURIComponent(output),
                   "_blank", "width=200,height=100");

        x = window.print();

        return false;
    }
</script>

我以this 为灵感:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-26
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多