当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Is there any way to use onmouseover and onmousedown together?

问题描述:

This code works fine for onMouseOver and onMouseOut events, but it doesn't work for onMouseDown.

Here is the code that I wrote in HTML5 and JavaScript. Let me know the mistakes that I am make. Please help.

Thanks in advance.

<!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>

网友答案:

you forgot to send the 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>

Check onmousedown="selection('zero');" and onmousedown="selection('cross');"

分享给朋友:
您可能感兴趣的文章:
随机阅读: