2015-10-13 95 views
1

我有这样的结构:访问内容

<body> 
<iframe name="here"> 
<iframe name="other"> 
</body> 

iframe的身体“其他”是:

<div id="content">foo</div> 

我如何可以访问的内容“等”从“这里”?

我想这改变内容:

$('#other',top.document).contents().find("#content").html("bar"); 

但这不起作用


最后我设法解决这个问题没有jQuery的:

top.frames['other].document.getElementById("content").innerHTML="bar" 

但如何用jquery解决这个问题仍然很有趣。

回答

0

有两种错误:

  • I帧这里identifyer的名字不是ID
  • 来访问实例在顶部文档中使用window.top.document

所以正确的方式从内部访问它是:

$('[name="other"]',window.top.document).contents().find("#content").html("foo"); 
0

'#' 用于在jQuery的IDS,对于名称需要使用$('[name="ElementNameHere"]').doStuff();