在特定坐标处触发 JavaScript click() 事件 [英] Triggering a JavaScript click() event at specific coordinates

查看:20
本文介绍了在特定坐标处触发 JavaScript click() 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图触发(触发)一个点击事件.在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.

本质上,我需要在特定位置触发点击(这是在 trigger() 调用之前计算的).

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

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

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

谢谢-

推荐答案

设置pageXpageY 属性(它们是标准化)在 事件对象 上并将其传递给 .trigger(),像这样:

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);

这篇关于在特定坐标处触发 JavaScript click() 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆