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

<!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 οnclick="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 οnclick="funClose();">关闭本窗口</button> <hr> 此文本框的值将要传递到父窗口 <input type="text" id="childText" value="子窗口的值:1"> </body> </html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值