jQuery改变了iFrame的内容 [英] jQuery changing contents of an iFrame

查看:128
本文介绍了jQuery改变了iFrame的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用jQuery完全不熟悉。为什么这不起作用?

I'm completely new to using jQuery. Why isn't this working?

<iframe width="800" scrolling="no" id="prev" src="">your browser needs to be updated.
</iframe>
<script src="jquery.js"></script>
<script>
    //var c = 0;
    $(document).ready(function() {
        $('#prev').contents().html("<html><body><div> blah </div></body></html>");
    })
</script>

此外,我打算使用此iFrame将html文件的更改预览呈现给用户。每次进行更改时,我要清空整个iFrame,或者如果我能弄清楚如何这样做,请使用jQuery更改特定行。这是最好的解决方法吗?

Also, I am planning on using this iFrame to present a preview of changes to an html file to a user. I am going to either empty the entire iFrame every time a change is made or, if I can figure out how to do so, change particular lines using jQuery. Is that the best way to go about this?

推荐答案

如果你想更新 iframe 使用html的内容然后你应该首先在 iframe 中找到 body 元素,然后附加所需内容标记。

If you want to update the iframe content using html then you should first find the body element inside the iframe and then append the required markup.

$(document).ready(function() {
    $('#prev').contents().find('body').html('<div> blah </div>');
});

工作演示 - http://jsfiddle.net/ShankarSangoli/a7r9L/

这篇关于jQuery改变了iFrame的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆