此代码适用于onMouseOver
和onMouseOut
个事件,但不适用于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>
答案 0 :(得分:4)
您忘了发送身份证件
<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');"