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>
  • 相关阅读:
    socket 网络编程
    错误与异常
    正则与计算器
    正则爬虫案例
    面向对象
    模块与包
    常用模块-----configparser & subprocess
    正则表达式&re模块
    常用模块---sys&logging&序列化模块(json&pickle)
    常用模块----time&random&hushlib&os
  • 原文地址:https://www.cnblogs.com/guohuiru/p/3225497.html
Copyright © 2011-2022 走看看