gpt4 book ai didi

javascript - 有没有办法同时使用 onmouseover 和 onmousedown ?

转载 作者:行者123 更新时间:2023-11-28 16:01:18 24 4
gpt4 key购买 nike

此代码适用于 onMouseOveronMouseOut 事件,但不适用于 onMouseDown。这是我用 HTML5 和 JavaScript 编写的代码。让我知道我所犯的错误。请帮忙。提前致谢。

<!DOCTYPE html>
<html>
<head>
<title>Zero cross</title>
</head>

<body>
<script>
function changecolor(vals) {
document.getElementById(vals).style.color = "red";
document.getElementById(vals).innerHTML = "Click to select";
}

function changeagain(vals) {
document.getElementById(vals).style.color = "#000000";
if (vals == 'cross') {
document.getElementById(vals).innerHTML = "X";
} else {
document.getElementById(vals).innerHTML = "0";
}
}

function selection(vals) {
document.getElementById(vals).style.color = "yellow";
if (vals == 'cross') {
document.getElementById(vals).innerHTML = "X";
} else {
document.getElementById(vals).innerHTML = "0";
}
}
</script>

<div align="center">
<p id="cross" onmouseover="changecolor('cross');" onmouseout="changeagain('cross');" onmousedown="selection();">
X
</p>
<p id="zero" onmouseover="changecolor('zero');" onmouseout="changeagain('zero');" onmousedown="selection();">
0
</p>

</div>

</body>

最佳答案

您忘记发送 ID

<p id="cross" onmouseover="changecolor('cross');" onmouseout="changeagain('cross');" onmousedown="selection('cross');">
X
</p>
<p id="zero" onmouseover="changecolor('zero');" onmouseout="changeagain('zero');" onmousedown="selection('zero');">
0
</p>

检查 onmousedown="selection('zero');"onmousedown="selection('cross');"

关于javascript - 有没有办法同时使用 onmouseover 和 onmousedown ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16881435/

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