0

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

4

1 回答 1

4

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

于 2013-06-02T09:28:00.787 回答