2013-04-29 43 views
0

蔭使用iframe從父這樣如何使用Jquery將文本分配給iFrame中的標籤?

<div id="Omit" class="Omit" style="display:none"> 
     <iframe src="Omission.aspx" width="1000" height="600"></iframe> 
    </div> 

在我Omission.aspx亞姆有一種標籤,我收到顯示我的Child.aspx有兩頁Parent.aspx和Child.aspx

蔭從父值在標籤,以顯示

<div class="Right"> 

     <p> 
      <strong style="color: #000;">Omit</strong> 
      <asp:Label ID="lblOne" runat="server" CssClass="lblOne" ClientIDMode="Static" ></asp:Label> 

     </p> 
    </div> 

這裏時,我指定文本標記IAM沒有得到

var Text = $(".ddlName option:selected").text(); //Dropdwon of Parent.aspx 

我需要被分配到標籤是在I幀 我已經試過這些方式作爲

$(".lblOne").text($(".ddlService option:selected").text()) 
    $(".lblOne").text(Text); 
    $('#<%= lblOne.ClientID %>').html(Text) 
    $('#<%= lblOne.ClientID %>').text(Text) 

蔭無法兵文本到標籤.., 任何人都可以請幫我從這個這個值小的情況分配的, 謝謝Advace

+0

看看這個回答我的:http://stackoverflow.com/questions/15884994/javascript- can-data-be-passed-bi-directionalally-through-an-iframe/15928562#15928562它稍微有點多,然後你需要,但可能你需要更晚。 – 2013-04-29 07:07:30

+2

Duplicate:http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe – 2013-04-29 07:10:18

+0

@ t.niese但是,這裏我沒有分配iframe的Jquery我只是想分配文本到標籤這是iframe的另一頁 – 2013-04-29 07:11:32

回答

2

試試這個:

// Get the iFrame jQuery Object 
var $MyFrame = $("#iframeid"); 

// You need to wait for the iFrame content to load first 
// So, that the click events work properly 
$MyFrame.load(function() { 
    var frameBody = $MyFrame.contents().find('body'); 

    // Find the label 
    var $label = frameBody.find('.lblOne'); 

    // Set the label text 
    $label.html(Text); 
}); 
+0

是的,它的工作 – 2013-04-29 07:21:22

相關問題