一区二区久久-一区二区三区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 兩個窗體之間傳值實現代碼,轉載需保留來源!

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

主站蜘蛛池模板: 黄色在线视频在线观看 | 91久久国产情侣真实对白 | 天天舔天天干 | 国产精品麻豆一区二区 | 深夜福利一区二区 | 精品视频一区二区三区在线播放 | 色欧美视频 | 欧美aav| 国产美女网 | 欧美精品v国产精品v日韩精品 | 国产成人精品福利网站在线观看 | 在线播放黄色 | 亚洲美女aⅴ久久久91 | 成人免费看视频 | 欧美成人三级网站在线观看 | 国产在线中文字幕 | 成人97在线观看免费高清 | 精品国产午夜久久久久九九 | 国产欧美一级片 | 国产欧美亚洲精品综合在线 | 日本人视频18jizz免费 | 自拍偷自拍亚洲精品被多人伦好爽 | 在线观看视频一区二区三区 | xfplay影音先锋永久资源 | 国内精品视频 | 中文福利视频 | 日本精品一区二区在线播放 | 好吊妞视频这里有精品 | 国产成人资源 | 亚欧免费视频一区二区三区 | 激情文学88 | 99精品伊人久久久大香线蕉 | 2021久久精品免费观看 | 国产成人精品一区二三区2022 | 国内成人免费视频 | 国产精品亚洲一区二区三区正片 | 久久精品中文字幕极品 | 亚洲午夜18| 看全色黄大色黄大片色责看的 | 成人a毛片手机免费播放 | 国产精品视_精品国产免费 国产精品视频1区 |