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

最佳答案

您忘了发送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');"

关于javascript - 有什么办法可以同时使用onmouseover和onmousedown吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16881435/

10-10 13:57