javascript 画布中的 Onclick 侦听器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15112343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 23:32:21  来源:igfitidea点击:

Onclick listener in canvas

javascripthtml

提问by Blitz

I am having a problem with adding a basic onclick listener in canvas in javascript, I want to retrieve the (x, y) coordinates for it, I would appreciate any help please.

我在 JavaScript 的画布中添加基本的 onclick 侦听器时遇到问题,我想检索它的 (x, y) 坐标,我将不胜感激。

Thank you.

谢谢你。

回答by Prasath K

Try this..

试试这个..

document.getElementById('canvasId').addEventListener('click',function(evt){
alert(evt.clientX + ',' + evt.clientY);
},false);