zoukankan      html  css  js  c++  java
  • JS 利用window.open实现post方式的参数传递

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script language="javascript">
    function openWindow(name) {
    window.open('about:blank', name, 'height=500,width=600,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no')
    }
    function openPostWindow(url, name, data1, data2) {
    var tempForm = document.createElement("form");
    tempForm.id = "tempForm1";
    tempForm.method = "post";
    tempForm.action = url;
    tempForm.target = name;

    var hideInput = document.createElement("input");
    hideInput.type = "hidden";
    hideInput.name = "WjId"
    hideInput.value = data1;
    tempForm.appendChild(hideInput);

    var hideInput2 = document.createElement("input");
    hideInput2.type = "hidden";
    hideInput2.name = "UserId"
    hideInput2.value = data2;
    tempForm.appendChild(hideInput2);

    if (window.addEventListener) {
    tempForm.addEventListener("onsubmit", function () { openWindow(name); });
    } else if (window.attachEvent) {
    tempForm.attachEvent("onsubmit", function () { openWindow(name); });
    }
    document.body.appendChild(tempForm);

    //tempForm.fireEvent("onsubmit");
    tempForm.submit();
    document.body.removeChild(tempForm);
    }


    function openNewWin() {
    openWindow("WjdcWin");//这一行很重要,网上好多方法没有这一行,导致打开一个新窗口,而不弹出一个小窗口。
    var wjId = document.getElementById("wjId").value;
    //alert(wjId);
    var userId = document.getElementById("userId").value;
    //alert(userId);
    openPostWindow("WinOpenPost2.aspx", "WjdcWin", wjId, userId);

    }

    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    问卷ID<input type="text" name="wjId" id="wjId" />
    用户ID<input type="text" name="userId" id="userId" />
    <input type="button" name="btnCc" value="传参数" onclick="openNewWin()" />
    </div>
    </form>
    </body>
    </html>

  • 相关阅读:
    java编译错误No enclosing instance of type TestFrame is accessible. Must qualify the allocation with an enclosing instance of type TestFrame (e.g. x.new A(
    java 2中创建线程方法
    动态规划基本思想
    关于eclipse编译一个工程多个main函数
    java Gui初识
    Eclipse中java项目的打包
    java 播放声音
    把资源文件夹导入到eclipse中
    Java建立JProgressBar
    How to grant permissions to a custom assembly that is referenced in a report in Reporting Services
  • 原文地址:https://www.cnblogs.com/itbob/p/3863598.html
Copyright © 2011-2022 走看看