0
<html>
<script>
document.write("<iframe id='theframe' src='http://www.website.com?testvr=" + testvr + " height='900' width='500'></iframe>");
</script>
</html>

添加了 iframe,但为 500 x 150 而不是 900 x 500。当 iframe 位于正文标签内时,此尺寸很好,并且仅在使用 document.write 时才这样做。为什么?

4

1 回答 1

2

首先,应用样式的正确方法是使用 style 属性。

<iframe id='theframe' src='yourComplexSrc' style='height:900px; width:500px;'></iframe>

最佳实践:将样式与标记分开。(样式应该转到不同的样式表文件)

但是,您的代码的问题是在src值之后,您没有结束标记。所以最终,这应该工作:

document.write("<iframe id='theframe' src='http://www.website.com?testvr=" + testvr + "' height='900' width='500'></iframe>");
于 2013-09-16T11:37:44.737 回答