子页面调用父页面的方法或者变量
window.parent.方法()或者变量名
window.parent相当于定位到父页面 之后的操作和在父页面中写代码一样写
例子:
window.parent.aa();//调取aa函数
window.parent.bb;//调取bb变量
jQuery - 子页面获取父页面元素
格式:$("#父页面元素id" , parent.document);
实例:$("#pBtnOk" , parent.document).click(); // pBtnOk 为父页面标签 id
例如:想在子页面中得到id为aaa的文本框的值
window.parent.$("#aaa").val();//这种写法的前提是引用了jquery
window.parent.getElementById("aaa").value; //js的写法
父页面调取子页面
主要是通过contentWindow定位到子页面
document.getElementById("childframe").contentWindow.childtest();
//调取子页面中的childtest方法 js的写法
var childWindow = $("#addFrame")[0].contentWindow;//获取子窗体中的对象
childWindow.formSubmit();//调取子页面的formSubmit方法 jquery的写法
//注释:其中 childframe和addFrame 都时iframe的id
jQuery - 父页面调用子页面方法
格式:$("#iframe的ID")[0].contentWindow.iframe方法();
实例:$("#ifm")[0].contentWindow().iClick(); // ifm 为 <iframe> 标签 id; iClick为子页面 js 方法
$("#iframe的ID").contents().find("#iframe中的控件ID");
格式:$("#iframe的ID").contents().find("#iframe中的控件ID").click();
实例:$("#ifm").contents().find("#iBtnOk").click(); // ifm 为 <iframe> 标签 id; iBtnOk 为子页面按钮 id