我不明白。我以爲我是這樣做的,現在我做不到了。 簡單的HTML與iframe。顯示iframe是另一個html。我想在訪問iframe時從主iframe中更改圖像。從主HTML HTML:無法從iframe訪問父元素
主HTML:
<!DOCTYPE HTML>
<html lang="en">
<head></head>
<body>
<img id="logo" src="../img/fpdfilms-logo-home.png" />
<iframe id="fondo" name="main" src="test.html"></iframe>
</body>
</html>
的test.html
<!DOCTYPE HTML>
<html lang="en">
<head></head>
<body>
<a href="#" onclick="change();">Change Picture</p>
<script src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
function change()
{
var $logo= $('#logo', window.parent.document);
alert("Does it work?");
$logo.attr("src","../img/fpdfilms-logo-director.png");
}
</script>
</body>
</html>
它應該改變圖片,當你點擊鏈接。但警報沒有顯示......我嘗試過不同的方式,我真的迷路了。實現這個簡單的改變是如此困難?
可能的重複[如何在jQuery中編寫此代碼] window.parent.document.getElementById('parentPrice')。innerHTML「?](http://stackoverflow.com/questions/726816/how-to-write-這在jquery窗口父母文件getelementbyidparentprice) – 2015-02-24 08:49:50