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

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

主站蜘蛛池模板: 国产成人亚洲精品 | 国产zzzwww在线观看视频 | 视频区小说区 | 91激情 | 91免费公开视频 | 免费视频不卡一区二区三区 | 5月丁香6月婷婷 | 蜜月aⅴ免费一区二区三区 免播放器在线观看 | 男女性色大片免费网站 | 一区二区精品在线观看 | 国产成人福利美女观看视频 | 四虎精品影视 | 国产高清福利91成人 | 中文在线第一页 | 久久精品99无色码中文字幕 | 色五月视频| 精品久久中文字幕有码 | 伊人精品线视天天综合 | 911精品国产91久久久久 | 国产精品区一区二区三 | 国产精品亚洲二区在线 | 欧美午夜久久 | 在线观看视频网站www色 | 日本加勒比一区 | 一区二区三区网站在线免费线观看 | 亚洲综合色网站 | 欧美在线网址 | 91久久精品青青草原伊人 | 黄视频在线 | 色综合成人 | 91在线视频免费看 | 国产成人亚洲精品 | 亚洲黄色免费观看 | 亚洲激情图片网 | 久热99这里只有精品视频6 | 国产亚洲高清视频 | 亚洲成人婷婷 | 欧美日韩国产一区二区三区伦 | 在线午夜视频 | 不卡视频一区二区 | 中文字幕精品在线观看 |