jQuery 更改 iFrame 的内容 [英] jQuery changing contents of an 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?
推荐答案
如果你想使用 html 更新 iframe
内容,那么你应该首先找到里面的 body
元素iframe
然后附加所需的标记.
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屋!