javascript模拟鼠标点击特定位置 [英] javascript simulate mouse click on specific position

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

问题描述

现在我需要如何自动触发按钮上的鼠标点击事件。
我有这个但不工作:(

I need to now how to fire a mouse click event on a button automatically. I have this but doesn't work :(

window.setInterval(function() { simulateClick(); }, 2000);

function simulateClick() {
    var evt = document.createEvent("MouseEvents");
    evt.initMouseEvent("click", false, false, window, 0, 684, 571, 684, 508, false, false, false, false, 0, null);
        var a;
    a.dispatchEvent(evt);
}

提前感谢

Oscar

推荐答案

如果所有你想做的是点击一个按钮,按钮元素有一个点击方法可以调用:

If all you want to do is click a button, button elements have a click method that can be invoked:

<input type="button" id="theButton" onclick="javascript:alert('The button was clicked!');" value="A button" />

<script language="javascript">

setTimeout(function(){
    document.getElementById("theButton").click();
}, 1000); // wait one second then click the button

</script>

没有必要实际模拟鼠标在特定x,y位置点击。

There's no need to "actually" simulate the mouse click at a specific x,y position.

这篇关于javascript模拟鼠标点击特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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