无法修改iframe的内容,有什么不对?

Sla*_*lay 9 html jquery

我试图修改iframe的内容,但它不起作用.

这是我的main.html

<html>
<head><title>Main page</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>

<h3>Main page</h3>
<iframe src="ifr.htm" id="ifr" name="ifr"></iframe>
</body>

<script>
$(document).ready(function(){
    $('#ifr').load(function(){
        $('#ifr').contents().find('body').html('Hey, i`ve changed content of <body>!    Yay!!!');
    });
});

</script>
</html>
Run Code Online (Sandbox Code Playgroud)

这是我的ifr.htm

<html>
<head><title>Iframe page</title></head>
<body>
 Content to be displayed in iframe ...
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Osc*_*car 17

请不要忘记该cross-domain政策,否则将无效.

现场演示: http ://jsfiddle.net/oscarj24/wTWjF/

(只是要知道,我没有使用404页面,看看)

试试这个:

$(document).ready(function(){
    $('#ifr').ready(function(){
        $(this).contents().find('body').html('Hey, I have changed the body content yay!');
    });
});?
Run Code Online (Sandbox Code Playgroud)