2012-04-09 26 views
0

這裏我的代碼:我必須iframe一個父母和其他孩子,我想要使用jquery獲得孩子的iframe值,我怎麼能得到?

<div id="biography_name1"> 
    <iframe id="Array___Frame" src="some_value" height="600" frameborder="0" width="100%" scrolling="no" > 
     <html> 
       <head></head> 
       <body> 
        <iframe src="some_value"> 
         <div class="my_value"> GET THIS VALUE </div> 
        </iframe> 
       </body> 
     </html> 
    </iframe> 
</div> 

在這裏,我想用jQuery來獲取類MY_VALUE值。我能怎麼做?

+0

似乎沒有乾淨的方法來做到這一點,但[這應該回答你的大部分問題](http://stackoverflow.com/questions/1654017/how-to-expose-iframes-dom-using -jquery)。 – faino 2012-04-09 09:01:46

回答

0

如果有幫助,不要忘記註冊並接受答案! ;)

<iframe id='frameParent'> 
    <iframe id='frameChild'> 
     <div id="my_value">some text here</div> 
    </iframe> 
</iframe> 
<script> 
    var foo = $("#frameParent").contents().find("#frameChild").contents().find(".my_value").text(); 
    //NOW YOUR VALUE IS STORED IN THE VARIABLE CALLED FOO 
    //change '#' to '.' in last find statement  
</script> 

現在它應該工作

+0

不,這是行不通的。它給出了空值。 – 2012-04-09 08:54:54

+0

再看一遍,我編輯它。現在它應該工作:) – 2012-04-09 08:58:02

+0

雅親愛的我試過這一個,但它只會在一個框架上工作,但我有父母和孩子的框架,我想從孩子獲得價值,所以我怎麼能得到? – 2012-04-09 09:12:02

0
$(".my_value").text(); 

將這樣做。

相關問題