zoukankan      html  css  js  c++  java
  • 父页面与子页面间相互传值

    父页面与子页面间相互传值

     

    1。子页面又父页面通过window.open弹出 
    子页面要向父页面传值,只要在document前面加window.opener即可。
    如:
    父页面:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <script language="javascript">
    function tanchu()
    {
    window.open("Untitled-5.html");   
    }
    </script>
    <body>
        <form id="form1" name="form1" method="post" action="">
            <label> <input type="submit" name="button" id="button" value="提交"
                onclick="tanchu()" />
            </label> <label> <input type="text" name="textfield" id="textfield" />
            </label>
        </form>
    </body>
    </html>

    子页面

     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <script language="javascript">
    function aaa()
    {
     window.opener.document.getElementByIdx('textfield').value='123123123';
    }
    </script>
    <body>
        <form id="form1" name="form1" method="post" action="">
            <label> <input type="submit" name="button" id="button" value="提交"
                onclick="aaa()" />
            </label>
        </form>
    </body>
    </html>
     

    2。子页面是iframe框架中的页面 子页面要向父页面传值,只要在document前面加parent即可。
    父页面

     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <body>
        <form id="form1" name="form1" method="post" action="">
            <label> <input type="text" name="textfield" id="textfield" />
            </label>
            <iframe id="myiframe" src="Untitled-3.html"></iframe>
        </form>
    </body>
    </html>
     

    子页面

     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <script language="javascript">
    function aa()
    { 
    var a=parent.document.getElementByIdx('textfield').value;
    alert(a); 
    }
    </script>
    <body>
        <form id="form1" name="form1" method="post" action="">
            <label> <input type="submit" name="button" id="button" value="提交"
                onClick="aa()" />
            </label>
        </form>
    </body>
    </html>
  • 相关阅读:
    推荐19个很有用的 JavaScript 库
    李开复:我对年轻人是分享经验 不是要当导师
    DotNET企业架构应用实践数据库表记录的唯一性设计的设计兼议主键设定原则
    cookies,session,viewstate浅析
    不是HR,Leader你到底需要招什么样的程序员(变形金刚?超人?可能吗!)
    IBatis.Net学习笔记系列文章
    学习mvc的一些资料
    数据库日常维护常用的脚本部分收录
    设定Grid行的颜色
    被WSS3.0耍了一把
  • 原文地址:https://www.cnblogs.com/GotoJava/p/7516364.html
Copyright © 2011-2022 走看看