iframe子页面调用父页面全局变量的方法

本文介绍了一种通过将父iframe中的全局变量赋值给主html页面,然后子iframe从主html中获取该值的方法。具体步骤包括在父iframe中定义全局变量、将其赋值给主html的变量,并在子iframe中直接使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

将父iframe中的全局变量赋值给主html

子iframe再从主html中得到该值。


 

主html:

stcc.html   

 var weaList = [];

父iframe:

WeatherMsg.html

全局变量:

var weatherNum_send = [];

获取weatherNum_send 的值:

	var len=$('table tbody tr').length;
	var totalNum=0;
	for(var i=0; i<len;i++){
   	 	if( $('table tbody tr').eq(i).find('input').is(":checked")){
   	 		weatherNum_send[totalNum] = weatherNum_list[i];
   	 		totalNum++;
   	 	}
	}

 赋值给stcc.html的变量:

parent.weaList=weatherNum_send; 

子iframe:

WeatherInfoToShip.html

直接使用parent.weaList:

msg.weatherNum[i]=parent.weaList[i];

  

 

转载于:https://www.cnblogs.com/wkcode/p/7908731.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值