子窗體如何傳值到父窗體并調(diào)用父窗體的函數(shù)
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <script> //供DEMO02_01頁面的關(guān)閉按鈕調(diào)用 function myFunction(v){ //alert("這里是父窗口中的函數(shù)"+v); document.getElementById("parentText").value=v; }
//打開新窗口 function openNewWindow(){ window.open("DEMO02_01.html","","height=300;width=300;location=0;status =0;toolbar=0");
}
</script> </head>
<body>
<button onclick="openNewWindow();">打開新窗口</button> <hr> 此文本框的值要從子窗口中取得 <input type="text" id="parentText"> </body> </html>
DEMO02_01.html
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <script> function funClose(){ //:調(diào)用父窗體(DEMO02.html)中的myFunction 函數(shù) //window.opener獲得父窗口的window對象的引用 并調(diào)用 myFunction () 函數(shù)在js中作為window的屬性 window.opener.myFunction(document.getElementById("childText").value);
window.close(); } </script>
</head>
<body> <button onclick="funClose();">關(guān)閉本窗口</button> <hr> 此文本框的值將要傳遞到父窗口 <input type="text" id="childText" value="子窗口的值:1"> </body> </html>
posted on 2008-06-15 04:31 shine_panda 閱讀(822) 評論(0) 編輯 收藏