在特定坐标处触发 JavaScript click() 事件

发布于 2024-09-01 22:21:20 字数 154 浏览 0 评论 0原文

尝试触发(触发)点击事件。在 jQuery 中很容易做到,但无法弄清楚如何设置事件的坐标并发送它们。

本质上,我需要在特定位置触发单击(在调用 trigger() 之前计算)。

有什么方法可以做到这一点(用 jQuery 或其他方式)?

谢谢 -

Trying to fire off (trigger) a click event. Its easy to do in jQuery, but cannot figure out how to set the coordinates of the event and send them along.

Essentially, I need to trigger a click at a specific location (which is calculated prior to the trigger() call).

Any way to do this (in jQuery or otherwise)?

Thanks -

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少年亿悲伤 2024-09-08 22:21:20

设置 pageXpageY 属性(已标准化)事件对象 并将其传递给 .trigger(),如下所示:

var e = new jQuery.Event("click");
e.pageX = 10;
e.pageY = 10;
$("#elem").trigger(e);

Set the pageX and pageY properties (which are normalized) on the event object and pass it to .trigger(), like this:

var e = new jQuery.Event("click");
e.pageX = 10;
e.pageY = 10;
$("#elem").trigger(e);
安静 2024-09-08 22:21:20

“.trigger()”调用接受一个“extraParameters”参数,我认为您可以用它来填充 XY 坐标。 文档

.trigger("click", [x, y]);

The ".trigger()" call accepts an "extraParameters" parameter that you could use to stuff the XY coords in I would think. Documentation

.trigger("click", [x, y]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文