js彈出窗口獲取父窗口的值

1.html

<html>
<head>
<title>1.html</title>

<script type="text/javascript">  
 function test() {  
        //彈出一個新窗口2.html
        window.open ('2.html')  
}
</script>

</head>
<body>
<input name="mytext" type="text" value="父頁面的值"  />
<input type="submit" name="Submit" value="打開新窗口" onclick="test();" />
</body>
</html>

=====將上面和下面代碼分別保存爲1.html和2.html,放置在同一目錄下==================

2.html

<html>
<head>
<title>2.html</title>

<script language="JavaScript"> 
 function loading() {
     //獲取父頁面控件“mytext”的值傳遞給本頁面的控件“mytext2”
     document.getElementById('mytext2').value = self.opener.document.getElementById('mytext').value;
 }
</script>

</head>
<body onLoad="loading();">
<form action=search.php name="form">
父頁面的值:<input name="mytext2" type="text">
</form>
</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章