gpt4 book ai didi

javascript - iframe 大小不正确

转载 作者:行者123 更新时间:2023-12-02 18:20:56 29 4
gpt4 key购买 nike

<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 位于 body 标记内时,此尺寸很好,并且仅在使用 document.write 时才这样做。为什么?

最佳答案

首先,应用样式的正确方法是使用 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>");

关于javascript - iframe 大小不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18826947/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com