javascript get x and y coordinates on mouse click

前端 未结 3 2178
甜味超标
甜味超标 2020-11-27 16:07

I have a little div tag that when I click it (onClick event), it will run the printMousePos() function. This is the HTML tags:

<
3条回答
  •  情书的邮戳
    2020-11-27 16:24

    simple solution is this:

    game.js:

    document.addEventListener('click', printMousePos, true);
    function printMousePos(e){
    
          cursorX = e.pageX;
          cursorY= e.pageY;
          $( "#test" ).text( "pageX: " + cursorX +",pageY: " + cursorY );
    }
    

提交回复
热议问题