2011-12-31 36 views
0

有人可以告訴我如何通過JavaScript訪問iframe中的label1嗎?轉到iframe中的標籤

WebForm1.aspx的

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div class="calendar"> 
     <iframe src="WebForm2.aspx"></iframe> 
    </div> 
    </form> 
</body> 
</html> 

WebForm2.aspx

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <table> 
      <tr><td class="default"><label id="label1">Label1</label></td></tr> 
     </table> 
    </div> 
    </form> 
</body> 
</html> 

回答

2

給的iframe的標識,例如說

<iframe src="WebForm2.aspx" id="webForm" ></iframe> 

然後爲了獲取該字段「lable1」你必須給下面的代碼

(document.getElementById("webForm")).contentWindow.document.getElementById("label1").innerHTML; 

希望這有助於你

+0

什麼是**呢? – ThinkingStiff 2011-12-31 06:44:17

+0

我編輯過,它出錯了 – AmGates 2011-12-31 06:49:25