要在JavaScript中找到光标的坐标,请使用event。clientX和event.clientY。您可以尝试运行以下代码来获取JavaScript中的光标坐标。
<!DOCTYPE html> <html> <head> <script> function coordinatesFunc(event) { document.write("Coordinate(X) = " + event.clientX + "<br>Coordinate(Y) = " + event.clientY); } </script> </head> <body> <div onmousedown="coordinatesFunc(event)">Click me to get coordinates of cursor</p> </body> </html>