使用javascript模拟点击x / y坐标 [英] Simulate click at x/y coordinates using javascript

查看:880
本文介绍了使用javascript模拟点击x / y坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用javascript或jquery模拟x / y坐标点击?

How can I simulate a click at x/y co-ordinates using javascript or jquery?

我将使用脚本多次,我希望脚本点击在位置一,然后位置二,然后三,然后四,所以一个。

I will use the script multiple times and I want the script to click on postion one then postion two then three then four and so one.

这是更好的没有移动鼠标光标,但如果它必须移动,那是很好。

It is better without moving the mouse cursor, but if it has to move then that is fine as well.

推荐答案

这实际上可以通过 document.elementFromPoint 方法。一个jQuery示例:

This can actually be accomplished with the document.elementFromPoint method. A jQuery example:

function simulateClick(x, y) {
    jQuery(document.elementFromPoint(x, y)).click();
}
simulateClick(100, 250);
simulateClick(400, 250);

编辑:这是一个工作示例: http://jsfiddle.net/z5YjY/

Here is a working example: http://jsfiddle.net/z5YjY/

这篇关于使用javascript模拟点击x / y坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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