1

我定义了一个javascript函数:

<script>
function expand()
{
  parent.getElementById("elementA").style.height = 300px;
}
</script>

我正在尝试将其称为 onClick:

<div id="elementB" onclick="expand()">Notif</div>

Web 控制台告诉我单击它时未定义扩展。

4

3 回答 3

8

You have a syntax error in your javascript, it should be '300px' (a string); This is why the script does not load (which web console probably also tells you), so the function is not defined.

于 2013-10-03T21:03:27.420 回答
4

Try putting quotes around 300px, i.e.

<script>
function expand()
{
    parent.getElementById("elementA").style.height = '300px';
}
</script>
于 2013-10-03T21:03:43.933 回答
0

分配高度值时,必须将其分配为字符串值。

<script type="text/javascript">
function expand()
{
  // Need to assign the value as a string
  parent.getElementById("elementA").style.height = '300px'; 
}
</script>

我假设这是在给定父引用的 iframe 内。如果没有,您可能希望将parent更改为document

于 2013-10-03T21:08:14.797 回答