javascript實現開啟表單以及表單間傳值

來源:互聯網
上載者:User

父表單js代碼(開啟子表單):

js_open 1 <script type="text/javascript">
 2         //開啟強制回應對話方塊 取得傳回值
 3         function OpenModalDialog() {
 4             //用一個value來接受傳回值
 5             var value = window.showModalDialog("ModalDialogChild.aspx", "ModalDialog", "dialogWidth=800px; dialogHeight=1000px; center:Yes; Help:No; Resizable:No; Status:no; edge:sunken");
 6             $("#txtMsg").val(value);
 7         }
 8 
 9         //通過window.open開啟表單 取得傳回值
10         function OpenWin() {
11             window.open("winChild.aspx", "window", "height=800,width=1000,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,location=no,status=no");
12         }
13     </script>

父表單頁面html:

html 1 <body>
 2     <form id="form1" runat="server">
 3     <div>
 4         <input type="button" id="btn" value="OpenModalDialog" onclick="OpenModalDialog();" />
 5         <br />
 6         <br />
 7         ModalDialog:<asp:TextBox ID="txtMsg" runat="server"></asp:TextBox>
 8         <br />
 9         <br />
10         <input type="button" id="Button1" value="OpenWin" onclick="OpenWin();" />
11         <br />
12         <br />
13         OpenWin:<asp:TextBox ID="txtWinMsg" runat="server"></asp:TextBox>
14     </div>
15     </form>
16 </body>子表單_強制回應對話方塊:ModalDialog 1 <head runat="server">
 2     <title></title>
 3     <script type="text/javascript">
 4         function GetValue() {
 5             //通過window.returnValue來傳回值到父表單 由父表單中定義的value接收
 6             window.returnValue = document.getElementById("txtMsg").value;
 7             window.close();
 8         }
 9     </script>
10 </head>
11 <body>
12     <form id="form1" runat="server">
13     <div>
14         <asp:TextBox ID="txtMsg" runat="server" onblur="GetValue();"></asp:TextBox>
15     </div>
16     </form>
17 </body>子表單_Window.Open頁面:window.open 1 <head runat="server">
 2     <title></title>
 3     <script type="text/javascript">
 4         function SetWinValue() {
 5             //window.opener為開啟該頁面的父頁面引用 可以用過引用來擷取父表單的控制項
 6             window.opener.document.getElementById("txtWinMsg").value = document.getElementById("txtMsg").value;
 7             //下面語句為了防止關閉頁面時 出現關閉提示
 8             window.opener = null;
 9             window.open('', '_self', '');
10             //關閉
11             window.close(); 
12         }
13     </script> 
14 </head>
15 <body>
16     <form id="form1" runat="server">
17     <div>
18         <input type="text" id="txtMsg" />
19         <input type="button" id="btn" value="給父表單賦值" onclick="SetWinValue();" />
20     </div>
21     </form>
22 </body>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.