获取父iframe的关联字段

一、关联字段的获取

有时候子子页面要获取iframe页面的值,来作为子页面与父页面的关联字段。先通过parent.document获取父页面的html元素,然后再在里面父页面要传到子页面的值。

父页面在body中添加input标签

if(edit){
	edit.click(function(){
		var orandid = _grid.getIds();
		if($("#orandid_view_act").length==0){
			$("body").append("<input id='orandid_view_act' type='hidden' value='"+orandid+"'/>");
		}else{
			$("#orandid_view_act").val(orandid);
		}
	})
}

子页面获取父页面的值

var orandid_view_act =  $("#orandid_view_act",parent.document).val();

有时候父页面有可能有多个iframe,子页面先找到其中包含要传递值的父iframe,然后再在iframe中找到对应的input标签

	afvButton.click(function(){
		debugger;
		var orandid = $($("body input[id='orandid_view_act']"),$("div[id='divMain']",$("body",parent.document)).context.activeElement).val();
		var volid = _grid.getIds();
		openWindow(volid+"&volType=1",orandid);
	})

前台jsp页面获取父元素传递的值

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ include file= "../../../../platform/incl/Include_Header.jsp" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<input id="root" type="hidden" value="${ctx }"/>
<input id="ids" type="hidden" value="<%=request.getParameter("ids") %>"/>
<input id="volType" type="hidden" value="<%=request.getParameter("volType") %>"/>
<input id="orandid" type="hidden" value="<%=request.getParameter("orandid") %>"/>

js获取jsp页面的值

var root = null;
var ids = null;
var xcbh = null;


$(document).ready(function() {
	debugger;
	root = $("#root").val();
	ids = $("#ids").val();
	volType = $("#volType").val();
	orandid = $("#orandid").val();
	initpage();
});

function initpage(){
	if(ids!="null"){
		readxctyz();
		readxctyzx();
	}
	var timer = "";
	$("#save").click(function(){
		xctyz();
		$(this).attr("disabled", true); 
		timer = setTimeout(function(){
			$("#save").attr("disabled", false); 
        },6000);

	})
}

猜你喜欢

转载自blog.csdn.net/qq_35029061/article/details/82728965