iframe嵌套,jq父页面获取子页面变量,Dom元素

1.父页面获取子页面id为“#st”的dom

var getSomething=$("iframe").contents().find("#st");

2获取多级iframe嵌套的dom元素

let getSomething = $("iframe").contents().find("iframe").contents().find("#something");

往后追加 contents().find("iframe")即可

3.父页面拿子页面的变量

var win = $("#mainFrame")[0].contentWindow;
//假如子页面有一个变量flag为false;想要更改它的值。
win.flag=true

4.

//1.在a.jsp中通过top.$.jBox.open打开一个弹窗弹窗中的内容为b.jsp
//2.b.jsp中通过<iframe>标签(id为indexIfm)嵌套着一个c.jsp
function toLike(a,unLikeIndex){
		top.$.jBox.open(
			"iframe:${ctxf }/index/toLike.do?unLikeIndex="+unLikeIndex, "匹配", 900,500, {
				buttons : {
					"关闭" : true,
					"确定" : "ok"
				},
				bottomText:"选中要匹配的内容,点击确定。",
				submit:function(v,h,f){
					if(v=="ok"){
//在a.jsp中获取c.jsp中的js元素testId
                                                testElement = h.find("iframe")[0].contentWindow.$("#indexIfm")[0].contentWindow.testId;
//在a.jsp中获取c.jsp中的dom元素,id为domId的<input>
                                                testDom = h.find("iframe")[0].contentWindow.$("#iframeId").contents().find("#domId").val();
//在a.jsp中获取c.jsp中标签名称为checkbox的所有元素
						obj = h.find("iframe")[0].contentWindow.$("#indexIfm")[0].contentWindow.document.getElementsByName("checkbox");
						}
                                }
                        });
                }

参考博客:https://blog.csdn.net/Just_Maybe/article/details/96143817

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值