Computer >> 컴퓨터 >  >> 프로그램 작성 >> JavaScript

JavaScript에서 screenX 마우스 이벤트의 역할은 무엇입니까?

<시간/>

이벤트가 발생하면 screenX 마우스 이벤트는 마우스 포인터의 수평 좌표를 반환합니다.

예시

다음 코드를 실행하여 screenX 구현 방법을 배울 수 있습니다. JavaScript의 마우스 이벤트.

<!DOCTYPE html>
<html>
   <body>
      <p onclick = "coordsFunc(event)">Click here to get the x (horizontal) and y (vertical) coordinates of the mouse pointer.</p>
      <script>
         function coordsFunc(event) {
            var x_coord = event.screenX;
            var y_coord = event.screenY;
            var xycoords = "X coords= " + x_coord + ", Y coords= " + y_coord;
            document.write(xycoords);
         }
      </script>
   </body>
</html>