學(xué)習(xí) 學(xué)習(xí) 再學(xué)習(xí)

          學(xué)習(xí)才是唯一的出路

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            31 隨筆 :: 1 文章 :: 8 評(píng)論 :: 0 Trackbacks
          window.showModalDialog(URL,dialogArgments.features) 打開(kāi)一個(gè)新窗口

          URL為要開(kāi)啟的網(wǎng)頁(yè)名字。
          dialogArgments為設(shè)定好傳遞給新視窗網(wǎng)頁(yè)的參數(shù),可以為任意數(shù)據(jù)類型。
          feature 與open()的類似,都是格式方面的設(shè)定。調(diào)用格式為featureName1:featureValue1:(分號(hào))featureName2:featureValue2:

          關(guān)于feature具體的參數(shù)我就不詳細(xì)寫(xiě)了,看名字就應(yīng)該知道什么用處了吧。
          certer , dialogHeight, dialogLeft,dialogTop,dialogWidth,help(是否顯示help按鈕,下同),status,resizeable
          值=1為yes,0為no.

          我認(rèn)為最重要的是dialogArgments,可以傳遞值到新的窗口。
          第二重要就是 它的返回值 window.returnValue.可以在showModalDialog開(kāi)啟的窗口關(guān)閉后前,回傳一個(gè)任意類型的值。

          dialogArgments  可以傳入一個(gè)變量,但是 我認(rèn)為最好是傳入一個(gè)window 這樣的話,不光你可以調(diào)用你前面定義的變量names 和a 等等,還可以取到前一個(gè)頁(yè)面上任何元素的值.如下面的代碼所示:

             <script language =javascript>
              alert(window.dialogArguments.names);
              alert(window.dialogArguments.a );
             
          // alert(window.dialogArguments.document.form1.t1.value)
              window.dialogArguments.a = "Hello World";  //可以改變WebFromA里面的變量的值
              window.dialogArguments.document.form1.t1.value  = "t1";//可以修改WebFrom1里面的TextBox的value;
             
             

          在WebFromB.aspx頁(yè)面 我們可以取到 names 和a 的值還可以取到WebFromA的值.,還可以給它賦值.
          整體的代碼如下:
          WebFromA.aspx
          <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormA.aspx.cs" Inherits="_5demo.ShowDig.WebFormA" %>

          <!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>無(wú)標(biāo)題頁(yè)</title>
              
          <script language=javascript>
              
          function fnA()
              
          {
                  names 
          = new Array(3);
                  names[
          0= "chenzhifeng";
                  names[
          1= "chenjiang";
                  
                  a
          = "shuhui";
               temp
          =   window.showModalDialog("WebFormB.aspx",window);
                 
          // alert(a);
                 document.getElementById("t3").value = temp;
              }

              
          </script>
          </head>
          <body>
              
          <form id="form1" runat="server">
              
          <div>
              
          <input type=text value ="feng" id = "t1" />
              
          <br />
              
              
          <input type=text value ="chen" id = "t2" />
              
          <input type=button value = "Click Me" onclick ="fnA();" id = "btn1" />
              
          <p>
              返回值:
          <input type = "text" id= "t3" />
              
          </div>
              
          </form>
          </body>
          </html>

          WebFormB.aspx 如下:
          <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormB.aspx.cs" Inherits="_5demo.ShowDig.WebFormB" %>

          <!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>無(wú)標(biāo)題頁(yè)</title>
              
          <script language =javascript>
             
          // alert(window.dialogArguments.names);
              alert(window.dialogArguments.a );
             
          // alert(window.dialogArguments.document.form1.t1.value)
              window.dialogArguments.a = "Hello World";  //可以改變WebFromA里面的變量的值
              window.dialogArguments.document.form1.t1.value  = "t1";//可以修改WebFrom1里面的TextBox的value;
             
             
              
          </script>
          </head>
          <body>
              
          <form id="form1" runat="server">
              
          <div>
              
          <input type=text id = "tt" value = "Hello ZiFeng"/>
              
          <script language =javascript>
              window.returnValue 
          = document.getElementById("tt").value;
              window.close();
              
          </script>
              
          </div>
              
          </form>
          </body>
          </html>

          在WebFormB.aspx中 window.returnValue是用于 返回給WebFromA.aspx的值.
          在WebFromA.aspx中,可以用一個(gè)變量來(lái)接收這個(gè)值 temp=   window.showModalDialog("WebFormB.aspx",window);

          J-CN工作室
          www.j-cn.org
          posted on 2009-12-15 20:59 鐵猴 閱讀(19140) 評(píng)論(7)  編輯  收藏 所屬分類: HTML相關(guān)

          評(píng)論

          # re: window.showModalDialog的傳值和返回值 2013-12-17 09:44 颯颯是
          颯颯  回復(fù)  更多評(píng)論
            

          # re: window.showModalDialog的傳值和返回值 [未登錄](méi) 2013-12-31 13:06 s
          sss  回復(fù)  更多評(píng)論
            

          # re: window.showModalDialog的傳值和返回值 2014-09-24 14:46 10
          101010  回復(fù)  更多評(píng)論
            

          # re: window.showModalDialog的傳值和返回值 2015-06-17 15:58 ertret
          eee  回復(fù)  更多評(píng)論
            

          # re: window.showModalDialog的傳值和返回值 2015-06-17 15:58 ertret
          eeee  回復(fù)  更多評(píng)論
            

          # re: window.showModalDialog的傳值和返回值 [未登錄](méi) 2015-10-30 11:25 test
          如果傳的值超長(zhǎng)怎么傳  回復(fù)  更多評(píng)論
            

          # re: window.showModalDialog的傳值和返回值 [未登錄](méi) 2016-04-14 14:56 77
          777  回復(fù)  更多評(píng)論
            

          主站蜘蛛池模板: 辽宁省| 秦皇岛市| 镇雄县| 土默特右旗| 吉首市| 什邡市| 肃南| 津市市| 丹寨县| 邵东县| 绵竹市| 昭平县| 西昌市| 阳东县| 天全县| 富顺县| 东至县| 博客| 英德市| 黄浦区| 晋宁县| 郧西县| 峨山| 神农架林区| 监利县| 焉耆| 平江县| 隆林| 仙游县| 广元市| 象州县| 德江县| 紫阳县| 金昌市| 宾川县| 曲松县| 英德市| 武鸣县| 曲阜市| 济阳县| 乌审旗|