gpt4 book ai didi

JavaScript 函数未定义错误 onmouseover

转载 作者:行者123 更新时间:2023-11-30 12:38:14 27 4
gpt4 key购买 nike

我正在尝试将段落堆叠在一起。当我将鼠标悬停时,我希望显示该特定段落。但是我收到错误:

未捕获的 ReferenceError:分配中的左侧无效

JS:

var topLayer = "p3";


function moveIt(toTop)
{
var oldTop = document.getElementById(topLayer).style;
var newTop = document.getElementById(toTop).style;

oldTop.z-index = "0";
newTop.z-index = "10";

topLayer = document.getElementById(toTop).id;
}

HTML:

<html>
<head>
<title>Text of Stacked Paragraph</title>
<link rel="stylesheet" href="stacked.css" type="text/css">
<script type="text/javascript" src="stacked.js"></script>
</head>
<body>
<p id="p1" class="para1" onmouseover="moveIt('p1')">
This is one of the paragraphs.
</p>
<p id="p2" class="para2" onmouseover="moveIt('p2')">
Another paragraph.
</p>
<p id="p3" class="para3" onmouseover="moveIt('p3')">
More paragraph.
</p>
</body>

我哪里做错了?

最佳答案

DOM 元素的 z-index 属性通过 zIndex 设置:

var topLayer = "p3";

function moveIt(toTop) {
var oldTop = document.getElementById(topLayer).style;
var newTop = document.getElementById(toTop).style;

oldTop.zIndex = "0";
newTop.zIndex = "10";

topLayer = document.getElementById(toTop).id;
}

Jsfiddle 示例:http://jsfiddle.net/d4LLfs6e/1/

关于JavaScript 函数未定义错误 onmouseover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25371589/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com