我试图通过在 iframe 内部设置 JS 来操作 iframe 外部的元素 style.backgroundColor 代码有效,但innerHtml 无效
我有
<script type="text/javascript">
//get main document element.
var ititle= parent.document.getElementById('MainTitle');
//works
ititle.style.backgroundColor = "#FFCC00";
//doesn't work
ititle.innerHtml='test html';
</script>
上面的脚本在我的 iframe 中
有什么原因吗?非常感谢。
最佳答案
因为 JavaScript 是区分大小写的,并且它是 innerHTML
(全部为大写):
ititle.innerHtml='test html';
//should be
ititle.innerHTML='test html';
关于javascript - 如何操作 iframe 之外的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12377468/