在父页面
<div id="main"></div>
<iframe src="子页面" />
$("#main").data('main_data',{'name':'izhangbo.cn'});
在iframe子页面中,如何获得 $("#main").data('main_data')
的值?
jQuery object itself is created inside anonymous function and it uses closure for accessing global (global for other jQuery functions) array inside this functions. So, as result: jQuery in iframe and jQuery in the top window have different data array. If you need top level data, use window.top.jQuery('#div1').data('test1') (please note that default context for jQuery is document, where it was initially created, so using "top level jQuery" we don't need to specify top level document.