此代码适用于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>