0

我有这个标题为 Criatweb 的父页面,其中有一个 iframe 页面,我想更改 iframe 页面内 div 的显示,但只有当它的标题是 Criatweb 时才更改。我在 iframe 页面中尝试过,但没有成功:

<script type="text/javascript">
if (window.parent.document.title == 'Criatweb')
{document.getElementById('customizarsite').style.display = 'none';}    
</script>
4

2 回答 2

1

错误消息意味着您在页面上加载元素之前调用它!

这就像在打开它之前穿过一扇门。除非你是鬼,否则不会发生。

您需要将其称为 onload 或 onready 或在元素之后。

<div id="customizarsite">Put the script after me</div>
<script type="text/javascript">
    if (window.parent.document.title == 'Criatweb') {    
        document.getElementById('customizarsite').style.display = 'none';
    }    
</script>
于 2013-01-24T03:15:31.527 回答
-1

使用jQuery 隐藏

<script type="text/javascript">
 if (window.parent.document.title == 'Criatweb')
 {
    $("#customizarsite").hide();
 }    
</script>
于 2013-01-24T02:57:05.367 回答