[javaScript] iframe內如何取得parent元素 (子頁面如何取得父元素) - S7an Insights

Breaking

S7an Insights

生活 × 技術 × 分享 讓複雜的問題,有條理地解決。

2017年11月9日 星期四

[javaScript] iframe內如何取得parent元素 (子頁面如何取得父元素)

//parent element
<...id = 'selB2Btype'...>
<...id = 'selRole'...>
<...id = 'selServiceType'...>


//iframe 
selB2Btype = $(window.parent.document).find('#selB2Btype').val();
selRole = $(window.parent.document).find('#selRole').val();
selServiceType = $(window.parent.document).find('#selServiceType').val();

如果iframe直接select 該3個id,並不會找到parent內的元素
但如果使用window.parent.document,便能順利取得在上一層內的元素值。


Ref : 

沒有留言:

張貼留言

問題沒有大小或好壞