【发布时间】:2014-07-25 11:57:56
【问题描述】:
我在 iframe 中编写 jQuery 脚本来隐藏 iframe 中的 h1
<iframe id = "preview" width="800" height="500">
</iframe>
<script>
var H = "<html><head><script>$(\'#hh\').toggle();<";
H+= "/script></head><body><h1 id='hh'>JavaScript</h1></body></html>";
var previewFrame = document.getElementById("preview");
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
preview.open();
preview.write(H);
preview.close();
</script>
但是,脚本看不到 iframe 中的元素。当我将 id='hh' 的元素移出 iframe 时,脚本可以工作。
【问题讨论】:
标签: javascript jquery html dom iframe