提交表单的数据,以弹出和打印弹出窗口

submit data of form to a popup and print that popup window

本文关键字:打印 窗口 表单 数据 提交      更新时间:2023-09-26

我使用这个代码从表单

获得提交的数据
<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>

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

edit: just to clarify more.
form submitted > open a new window > displays the entered results

谢谢

你可以这样修改代码:

<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>

我想你应该是这样的

<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>

我用这个作为灵感:)