javascript - 样式和 JavaScript 不工作

标签 javascript html iframe

我的以下内容似乎适用于 Internet Explorer,但不适用于 Chrome。谁能解释一下原因,以及我应该采取什么措施来纠正它。

<iframe id="confirmed_list" src="./meets/confirmed.php?meet_id=$1" scrolling="no" width="80%" onload="document.getElementById('confirmed_list').height = confirmed_list.document.body.scrollHeight">
</iframe>

脚本应自动扩展 iframe 的高度以适应内容。 Internet Explorer 获得了正确的值,但 Chrome 似乎严重错误地计算了该值。

有什么想法吗?

最佳答案

再仔细看看这里发生了什么:

document.getElementById('confirmed_list').height = confirmed_list.document.body.scrollHeight

在此事件处理程序中,从未定义过confirmed_list。我确定您指的是 document.getElementById( 'confirmed_list' )

无论如何,更好的解决方案是使用 this,因为它引用 iframe:

this.height = this.document.body.scrollHeight

关于javascript - 样式和 JavaScript 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4036213/

相关文章:

javascript - 确定 ExtendScript 中选定文本的 "tags"

javascript - 如何在html选项中添加onClick?

javascript - 单击时,使用 jQuery 将类添加到替代 div

java - 帧ID动态变化-如何用java收集那些id selenium webdriver

javascript - 我似乎无法将我的 vimeo iframe 静音

html - iframe 将内容从相邻元素向下移动

javascript - Node.JS 中的异步

javascript - hasOwnProperty 和 ECMAScript 5 严格模式

javascript - AND 多个参数

javascript - 关闭网页上的对话窗口