zoukankan      html  css  js  c++  java
  • 两个iframe之间传值

    例如:点击后会把另一个iframe中的值得到弹出

    Main:

    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <iframe id="A" src="A.html" height="300"></iframe>
        <iframe id="B" src="B.html" height="300"></iframe>
    </body>
    </html>

    页面A.html

    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script type="text/javascript">
    
         
            function GetPhone () {
                var phone = ""
                var rdos = document.getElementsByName("rdo");
                for (var i = 0; i < rdo.length; i++) {
                    if (rdos[i].checked) {
                        phone = document.getElementById(rdos[i].id + "_demo").value;
                        return phone;
                    }
                }
            }
          
        </script>
    </head>
    <body>
        移动:
        <input type="radio" name="rdo" id="mobile" />
        <input type="text" name="name" id="mobile_demo" /><br />
        固话: 
        <input type="radio" name="rdo" id="tel" />
        <input type="text" name="name" id="tel_demo" />
        </body>
    </html>

    页面B,调用页面A的js方法得到用户选择的电话

    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script type="text/javascript">
            window.onload = function () {
                document.getElementById("btn").onclick = function () {
                    var tel = parent.A.GetPhone();//调用页面A方法
                    alert(tel);
                }
            }
    
        </script>
    
    </head>
    <body>
        <input type="button" name="" value="点我!" id="btn" />
    </body>
    </html>
  • 相关阅读:
    jquery基础整理(面试必备)
    ES中文学习指南---入门篇
    ES的Java Rest client---jest
    java学习路线
    ES中文学习指南一-----产品体验
    Tomcat无法启动
    Maven问题集
    informatica9.5.1资源库为machine in exclusive mode(REP_51821)
    程序员书单_架构设计篇
    Informatica9.6.1在Linux Red Hat 5.8上安装遇到的有关问题整理_1
  • 原文地址:https://www.cnblogs.com/guohuiru/p/3225497.html
Copyright © 2011-2022 走看看