[英]Is there any way to use onmouseover and onmousedown together?
這段代碼對於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>
您忘記發送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');"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.