如何學(xué)好java

          如何學(xué)好java,其實(shí)很簡單,只要用心體會,慢慢積累!
          posts - 106, comments - 7, trackbacks - 0, articles - 3
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          基本介紹:
                    showModalDialog()         (IE 4+ 支持)
                    showModelessDialog()      (IE 5+ 支持)
                    window.showModalDialog()                  方法用來創(chuàng)建一個顯示HTML內(nèi)容的模態(tài)對話框。
                    window.showModelessDialog()             方法用來創(chuàng)建一個顯示HTML內(nèi)容的非模態(tài)對話框。
          使用方法:
                    vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
                    vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures])
          參數(shù)說明:
                   sURL          --  必選參數(shù),類型:字符串。用來指定對話框要顯示的文檔的URL。
                   vArguments    -- 可選參數(shù),類型:變體。用來向?qū)υ捒騻鬟f參數(shù)。傳遞的參數(shù)類型不限,包括數(shù)組等。對話框通過
           

                                    window.dialogArguments來取得傳遞進(jìn)來的參數(shù)。
                   sFeatures     -- 可選參數(shù),類型:字符串。用來描述對話框的外觀等信息,可以使用以下的一個或幾個,用分號“;”隔開。
          ----------------
          1.    dialogHeight:    對話框高度,不小于100px
          2.    dialogWidth:    對話框?qū)挾取?br />3.    dialogLeft:     離屏幕左的距離。
          4.    dialogTop:     離屏幕上的距離。
          5.    center:          { yes | no | 1 | 0 } :              是否居中,默認(rèn)yes,但仍可以指定高度和寬度。
          6.    help:             {yes | no | 1 | 0 }:                是否顯示幫助按鈕,默認(rèn)yes。
          7.    resizable:       {yes | no | 1 | 0 } [IE5+]:     是否可被改變大小。默認(rèn)no。
          8.    status:          {yes | no | 1 | 0 } [IE5+]:      是否顯示狀態(tài)欄。默認(rèn)為yes[ Modeless]或no[Modal]。
          9.    scroll:            { yes | no | 1 | 0 | on | off }:是否顯示滾動條。默認(rèn)為yes。

          下面幾個屬性是用在HTA中的,在一般的網(wǎng)頁中一般不使用。
          10.    dialogHide:{ yes | no | 1 | 0 | on | off }:在
          打印或者打印預(yù)覽時(shí)對話框是否隱藏。默認(rèn)為no。
          11.    edge:{ sunken | raised }:指明對話框的邊框樣式。默認(rèn)為raised。
          12.    unadorned:{ yes | no | 1 | 0 | on | off }:默認(rèn)為no。

          參數(shù)傳遞:
          1. 要想對話框傳遞參數(shù),是通過vArguments來進(jìn)行傳遞的。類型不限制,對于字符串類型,最大為4096個字符。也可以傳遞對象,例如:
          -------------------------------
          parent.htm
          <script>
                    var obj = new Object();
                    obj.name="51js";
                    window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
          </script>
          modal.htm
          <script>
                    var obj = window.dialogArguments
                    alert("您傳遞的參數(shù)為:" + obj.name)
          </script>
          -------------------------------
          2.可以通過window.returnValue向打開對話框的窗口返回信息,當(dāng)然也可以是對象。例如:
          ------------------------------
          parent.htm
          <script>
                    str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");
                    alert(str);
          </script>
          modal.htm
          <script>
                    window.returnValue="http://homepage.yesky.com";
          </script>

          常見技巧:

          一、怎樣才讓在showModalDialog和showModelessDialog的超連接不彈出新窗口?
            在被打開的網(wǎng)頁里加上<base target="_self">就可以了。這句話一般是放在<head>之間的。

          二、怎樣才刷新showModalDialog和showModelessDialog里的內(nèi)容?
            在showModalDialog和showModelessDialog里是不能按F5刷新的,又不能彈出菜單。這個只能依靠

          javascript了,以下是相關(guān)代碼:

          <body onkeydown="if (event.keyCode==116){reload.click()}">
          <a id="reload" href="filename.htm" style="display:none">reload...</a>

            將filename.htm替換成網(wǎng)頁的名字然后將它放到你打開的網(wǎng)頁里,按F5就可以刷新了,注意,這個要

          配合<base target="_self">使用,不然你按下F5會彈出新窗口的。

          三、如何用javascript關(guān)掉showModalDialog(或showModelessDialog)打開的窗口。
            <input type="button" value="關(guān)閉" onclick="window.close()">
            也要配合<base target="_self">,不然會打開一個新的IE窗口,然后再關(guān)掉的。

          四、Math.random與showModalDialog。

             當(dāng)你設(shè)置的彈出網(wǎng)頁固定時(shí)(如上面的"modal.htm"頁面),ie很可能到臨時(shí)文件區(qū),下載上次產(chǎn)生的該頁面(openPage.html),而沒有重新加載,

             對于動態(tài)加載的頁面來說,這樣往往產(chǎn)生誤會,如沒有及時(shí)更新數(shù)據(jù),也就更不利于開發(fā)者測試。所以,你可以采用如下方式:

                var strPage = “/medal.htm?random="+Math.random();

             這樣每次產(chǎn)生的strPage是不一樣的,原因也就不言自明了。

           

          下面舉兩個例子

          一、返回一個字符串

          首先是父頁面有個按鈕,用來打開Modal頁面userList.aspx

          復(fù)制代碼
           function openWin()
              {
                   str =window.showModalDialog("userList.aspx",window,"status:0;help:0;edge:sunken;dialogWidth=700px;dialogHeight=400px");

                  if(str!=undefined && typeof(str)!=undefined && str!="undefined" && str!="")
                  {
                    document.getElementById("txtuserid").value=str;
                  }else
                  {
                   document.getElementById("txtuserid").value="";
                  }
              }
          復(fù)制代碼

          str就是子頁面返回過來的數(shù)據(jù),我們把它添加到父類的一個表單元素中

          子頁面

              function getValue()
                  {          
                   var selectValue=$(":radio:checked").val();
                   window.returnValue=selectValue;
                   window.close();
                  }

          在這里我們把子頁面里的值返回到父頁面里就可以了,然后關(guān)閉頁面就可以了

          二、返回一個數(shù)據(jù)

          父頁面

          復(fù)制代碼
               function openWin()
               {
           
                  array =window.showModalDialog("demo2.aspx",window,"status:0;help:0;edge:sunken;dialogWidth=700px;dialogHeight=400px;scroll:no");
                 
                    document.getElementById("username").value=array[0];
                    document.getElementById("sex").value=array[0];
                   
               
              }
          復(fù)制代碼

          子頁面

           

          復(fù)制代碼
             function getValue()
                 {
                   var array=new Array();
                   
                   array[0]=document.getElementById("username").value;
                   Array[1]=document.getElementById("sex").value;
                   window.returnValue=array;
                   window.close();
                 }
          復(fù)制代碼

          返回一個數(shù)組就可以了,如果用open打開的話,在搜狗或者360瀏覽器打開的是一個頁面或者阻攔什么的

           前段時(shí)間在后臺使用JS的winodw.showModalDialog來查看靜態(tài)頁面內(nèi)容,發(fā)現(xiàn)不能及時(shí)顯示更新后的頁面內(nèi)容,用open打開有時(shí)也會出現(xiàn)這種問題

          解決辦法 
            window.showModalDialog(getUrl+"?Rnd="+Math.random(),"","dialogWidth:600px;dialogHeight:400px;help:no;scroll:yes;center:yes;status:no;");
          這樣就不會有緩存了

          多思考,多創(chuàng)新,才是正道!

          評論

          # re: JS中showModalDialog 詳細(xì)使用   回復(fù)  更多評論   

          2014-12-22 11:29 by 讓他
          通天塔
          主站蜘蛛池模板: 神农架林区| 白山市| 炉霍县| 铜鼓县| 鄂托克前旗| 娄底市| 弥渡县| 葫芦岛市| 新兴县| 屏山县| 基隆市| 伊春市| 建平县| 大同县| 陈巴尔虎旗| 自治县| 松潘县| 军事| 垫江县| 陆丰市| 滕州市| 嘉鱼县| 婺源县| 乌鲁木齐县| 天水市| 珠海市| 航空| 青冈县| 扎囊县| 海宁市| 石阡县| 锡林郭勒盟| 兴义市| 丰台区| 土默特左旗| 武定县| 嘉义县| 鄂温| 张北县| 平陆县| 北川|