一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

Javascript 兩個窗體之間傳值實現代碼

如我們新建窗體FatherPage.htm:
XML-Code:
復制代碼 代碼如下:
<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來訪問父窗體中的元素:
XML-Code:
復制代碼 代碼如下:
<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()" />

其實在打開子窗體的同時,我們也可以對子窗體的元素進行賦值,因為window.open函數同樣會返回一個子窗體的引用,因此FatherPage.htm可以修改為:
XML-Code:
復制代碼 代碼如下:
<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()" />

通過判斷子窗體的引用是否為空,我們還可以控制使其只能打開一個子窗體:
XML-Code:
復制代碼 代碼如下:
<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()" />

光這樣還不夠,當關閉子窗體時還必須對父窗體的child變量進行清空,否則打開子窗體后再關閉就無法再重新打開了:
XML-Code:
復制代碼 代碼如下:
<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>

JavaScript技術Javascript 兩個窗體之間傳值實現代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 综合婷婷 | 中文字幕成人网 | www激情com| 91精品福利 | 91九色在线播放 | 精品久久久中文字幕一区 | 久久精品国产精品青草 | 久色 | 在线观看免费视频国产 | 国内自拍视频在线看免费观看 | 看全色黄大色黄大片色黄看的 | 色偷偷网址 | 国产欧美激情一区二区三区 | 中文字幕视频一区二区 | 国产嫩草在线观看 | 巨胸喷奶水www久久久免费观看 | 在线亚洲一区二区 | 久久久噜噜噜久久久 | 国产天堂视频 | 国产成人精品在视频 | 婷婷综合丁香 | 久久影视网 | a级精品国产片在线观看 | 91在线看片一区国产 | 黄色大片免费看 | www.999精品视频观看免费 | 亚洲精品国产网红在线 | 国产精品美女一区二区 | 午夜免费视频网站 | 亚洲国产高清一区二区三区 | 久久中文娱乐网 | 黄网免费在线观看 | 一区二区三区免费在线 | 深爱激情婷婷 | 日本一区二区三区四区视频 | 欧洲成人r片在线观看 | 国产高颜值露脸在线观看 | 野外一男一女一级毛片 | 色婷婷影视 | 成人欧美日韩视频一区 | 日韩亚洲国产欧美精品 |