有没有办法一起使用onmouseover和onmousedown?

时间:2013-06-02 09:24:15

标签: javascript html5 events

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

1 个答案:

答案 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');"