Getting associated fields
Sometimes a child page needs to get the value of the iframe page as the associated field between the child page and the parent yemi page. First obtain the html element of the parent page through parent.document, and then transfer the value of the parent page to the child page.
The parent page adds the input tag to the body
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); } }) }
Child page gets the value of the parent page
var orandid_view_act = $("#orandid_view_act",parent.document).val();
Sometimes the parent page may have multiple iframes. The child page first finds the parent iframe containing the value to be passed, and then finds the corresponding input tag in the iframe
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); })
The foreground jsp page gets the value passed by the parent element
<%@ 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 get the value of jsp page
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); }) }
window.document object: represents the entire HTML document, which can be used to access all elements in the page.
$($($("div[class='panel window']",$(window.document.body)).last())[0]).css("top","280px")
jQuery.parent(expr) finds the parent node, which can be passed in to expr for filtering, such as $("span").parent() or $("span").parent(".class")
jQuery.parents(expr), similar to jQuery.parents(expr), but looking for all ancestor elements, not limited to the parent elements
$("#reloadGrid",$("body",parent.$("#cell").context)).click();