子窗体如何传值到父窗体并调用父窗体的函数

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <script>  //供DEMO02_01页面的关闭按钮调用  function myFunction(v){   //alert("这里是父窗口中的函数"+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(){      //:调用父窗体(DEMO02.html)中的myFunction 函数   //window.opener获得父窗口的window对象的引用 并调用 myFunction () 函数在js中作为window的属性   window.opener.myFunction(document.getElementById("childText").value);

  window.close();  } </script>

</head>

<body> <button onclick="funClose();">关闭本窗口</button> <hr> 此文本框的值将要传递到父窗口 <input type="text" id="childText" value="子窗口的值:1"> </body> </html>

posted @ 2008-06-15 12:31  shine_panda  阅读(731)  评论(0编辑  收藏  举报