• 同一页面的两个Iframe,其中一个iframe获取另一个iframe内的iframe中的元素值


    公共父页面(主页面):

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'test.jsp' starting page</title>
        
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
    
      </head>
      
      <body>
              <input id="test"/>
            <iframe id="iframe1" src="a.jsp"></iframe>
            <iframe id="iframe2" src="b.jsp"></iframe>
      </body>
    </html>

    a页面:

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'a.jsp' starting page</title>
        
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
        <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
      </head>
      
      <body>
            a页面
            
            <script type="text/javascript">
                $(function(){
                    setTimeout(function(){
                        var x = window.parent.document.getElementById("iframe2");  
                        var right = (x.contentWindow || x.contentDocument);  
                        if(right.document){  
                            right = right.document;  
                        }
                        alert(right.frames["iframe3"].window.document.getElementById("testId").value);
                    },100);
                })
            </script>
      </body>
    </html>

    b页面:

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'b.jsp' starting page</title>
        
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
      </head>
      
      <body>
            b页面
            <input type="text" value="我是b页面啊"/>
            <iframe id="iframe3" src="c.jsp"></iframe>
      </body>
    </html>

    c页面:

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'c.jsp' starting page</title>
        
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
        <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
      </head>
      
      <body>
            <input id="testId" value="我是b页面的子页面啊"/>
            <script type="text/javascript">
                $(function(){
                    var testVal = $("#testId").val();
                    window.parent.parent.document.getElementById("test").value = testVal;
                })
            </script>
      </body>
    </html>

    效果图:

  • 相关阅读:
    Runoob-Java:Java 开发环境配置
    公司-科技:JotSpot
    服务-WiKi:WiKi
    国际组织-Java:JCP
    Java:Java 简介
    Runoob-Java:Java 教程
    oracle-ofa
    HTML5 viewport 标签与 CSS3 background-size 属性 使图片完全适应区域内容
    Android studio怎么导入Recycler VIew
    Android studio怎么导入Recycler VIew
  • 原文地址:https://www.cnblogs.com/henuyuxiang/p/7427155.html
Copyright © 2020-2023  润新知