2013-05-26 51 views
0

我發現了一些奇怪的東西,也許有工作?jQuery:通過數據屬性從iframe中獲取父文檔中的元素

我有一個選擇:[data-pcId=1369592034]

// alerts 1, it finds the carousel in the parent document which 
//has the attribute: data-pcId="1369592034" 
alert($('.carousel', window.parent.document).length); 

// alerts 0, so not found 
alert($(selector, window.parent.document).length); 

當我在Firebug型$(selector, window.parent.document)$(selector)確實找到元素,當然這兩個查詢實際上是在做同樣的,因爲它會檢查以外的元素iframe然後window.parent.documentdocument相同

+0

而問題是? – adeneo

+0

[**適合我**](http://jsfiddle.net/doktormolle/JFFtN/) –

回答

1

我發現選擇器需要引號.... [data-pcId =「1369592034」]。仍然很奇怪,它沒有他們在Firebug工作

0

如果窗口具有不同的域(安全性),它將不起作用。否則它會。請參閱Dr. Molle的第二條評論。

+0

我發現選擇器需要引號.... [data-pcId =「1369592034」]。仍然奇怪它在Firebug中沒有它們 – poashoas

相關問題