久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

JavaScript學(xué)習(xí)筆——window對象使用

 四兩哥 2011-08-23

window對象是JavaScript瀏覽器對象模型中的頂層對象,,包含多個常用方法和屬性:

1 打開新窗口

window.open(pageURL,name,parameters)

其中:

pageURL為子窗口路徑

name為子窗口句柄

parameters為窗口參數(shù)(各參數(shù)用逗號分隔)

     如:window.open("http://www.cnblogs.com/zhouhb/","open",

'height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');

2 打開模式窗口

      window.showModalDialog("http://www.cnblogs.com/zhouhb/","open","toolbars=0;width=200;height=200");

3 關(guān)閉窗口

        window.opener=null;   //不彈出提示框
        window.close();

4 location對象使用

      window.location.reload();//刷新當(dāng)前頁

      window.location.;  //載入其他頁面

5 history對象使用

    window.history.go(1);  //前進(jìn)

     window.history.go(-1);  //后退

6 子窗體向父窗體傳值

6.1 簡單方法  

(1)在父窗體中打開子窗體

         var str=window.showModalDialog("s.html");
         if(str!=null)  
        {              
           var v=document.getElementById("v");
           v.value+=str;        
        }

(2)子窗體代碼

    var v=document.getElementById("v");
    window.parent.returnValue=v.value;

    window.close();

 6.2 更加詳細(xì)的介紹

    眾所周知window.open() 函數(shù)可以用來打開一個新窗口,那么如何在子窗體中向父窗體傳值呢,,其實通過window.opener即可獲取父窗體的引用。 
如我們新建窗體FatherPage.htm:
<script type="text/javascript">
function OpenChildWindow()
{
    window.open('ChildPage.htm');   
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="OpenChild" onclick="OpenChildWindow()" />

然后在ChildPage.htm中即可通過window.opener來訪問父窗體中的元素:
<script type="text/javascript">
function SetValue()
{
    window.opener.document.getElementById('txtInput').value
        =document.getElementById('txtInput').value;
    window.close();
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="SetFather" onclick="SetValue()" />

其實在打開子窗體的同時,,我們也可以對子窗體的元素進(jìn)行賦值,,因為window.open函數(shù)同樣會返回一個子窗體的引用,因此FatherPage.htm可以修改為:
<script type="text/javascript">
function OpenChildWindow()
{
    var child = window.open('ChildPage.htm');  
    child.document.getElementById('txtInput').value
        =document.getElementById('txtInput').value; 
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="OpenChild" onclick="OpenChildWindow()" />

通過判斷子窗體的引用是否為空,,我們還可以控制使其只能打開一個子窗體:

<script type="text/javascript">
var child
function OpenChildWindow()
{
    if(!child)    
        child = window.open('ChildPage.htm');  
     child.document.getElementById('txtInput').value
            =document.getElementById('txtInput').value; 
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="OpenChild" onclick="OpenChildWindow()" />

光這樣還不夠,,當(dāng)關(guān)閉子窗體時還必須對父窗體的child變量進(jìn)行清空,否則打開子窗體后再關(guān)閉就無法再重新打開了:
<body onunload="Unload()">
<script type="text/javascript">
function SetValue()
{
    window.opener.document.getElementById('txtInput').value
        =document.getElementById('txtInput').value;
    window.close();
}
function Unload()
{
    window.opener.child=null;
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="SetFather" onclick="SetValue()" />
</body>

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點擊一鍵舉報,。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多