2013-03-12 55 views
0

我有下面的html,我的iframe ID是動態生成的,現在我想更改我的span的html。如何使用jquery更改iframe中的html

<a title="Visit Us on Google+" id="gPlus" class="addthis_button_google_plusone at300b" g:plusone:count="false"> 
    <div id="___plusone_0"> 
    <iframe width="100%" scrolling="no" frameborder="0" hspace="0" marginheight="0" marginwidth="0" 
    style="position: static; top: 0px; width: 24px; margin: 0px; border-style: none; left: 0px; visibility: visible; height: 15px;" 
    tabindex="0" vspace="0" id="I0_1363080003291" name="I0_1363080003291" 
    src="https://plusone.google.com" 
    allowtransparency="true" data-gapiattached="true" title="+1"> 
     <html lang="en" dir="ltr"> 
      <head> 
      </head> 
      <body class="g-rba-Dh-kQa "> 
       <div class="Bg" dir="ltr" id="plusone"> 
       <span id="widget_bounds"><table cellspacing="0" cellpadding="0"><tbody><tr><td> 
       <div class="ZRa"> 
       <span tabindex="0" role="button" title="" class="hAa Ro Bg" id="button" aria-label="Click here to publicly +1 this." aria-pressed="false"><div class="YIa"></div></span></div></td></tr></tbody></table></span></div> 
      </body> 
     </html> 
    </iframe> 
    </div> 
</a> 

現在我想在「標題」標籤添加一些值使用jQuery

<div class="ZRa"> 
<span tabindex="0" role="button" title="" class="hAa Ro Bg" id="button" aria-label="Click here to publicly +1 this." aria-pressed="false"><div class="YIa"></div></span> 
</div> 

請建議!

+2

同源策略到位。您無法更改來自其他域的頁面標記。 – BenM 2013-03-12 10:14:43

+0

@BenM,這裏沒有跨域,因爲你的html在你的頁面上呈現,然後你需要編寫一些jquery函數,它會發現iframe並將其更改爲html,請建議! – 2013-03-12 10:19:33

+1

但是iframe的'src'是'plusone.google.com'? – BenM 2013-03-12 10:20:24

回答

0

試試這一次,

$(document).ready(function() { 
$("#___plusone_0") 
    .find("iframe") 
    .contents() 
    .find(".hAa ") 
    .attr('title', 'whatever u want'); 
}); 
+0

它沒有變化! – 2013-03-12 10:27:29

+0

你可以創建一個小提琴嗎? – 2013-03-12 10:33:20

+0

實際上它似乎jquery無法找到正在嘗試獲取的html,任何其他建議! – 2013-03-12 10:39:10

0

試試這個

$('#___plusone_0').find('span#button').attr('title','yourTitle'); 
+0

它不會改變使用上面的代碼 – 2013-03-12 10:28:08