我定义了一个javascript函数:
<script>
function expand()
{
parent.getElementById("elementA").style.height = 300px;
}
</script>
我正在尝试将其称为 onClick:
<div id="elementB" onclick="expand()">Notif</div>
Web 控制台告诉我单击它时未定义扩展。
我定义了一个javascript函数:
<script>
function expand()
{
parent.getElementById("elementA").style.height = 300px;
}
</script>
我正在尝试将其称为 onClick:
<div id="elementB" onclick="expand()">Notif</div>
Web 控制台告诉我单击它时未定义扩展。
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.
Try putting quotes around 300px, i.e.
<script>
function expand()
{
parent.getElementById("elementA").style.height = '300px';
}
</script>
分配高度值时,必须将其分配为字符串值。
<script type="text/javascript">
function expand()
{
// Need to assign the value as a string
parent.getElementById("elementA").style.height = '300px';
}
</script>
我假设这是在给定父引用的 iframe 内。如果没有,您可能希望将parent更改为document。