如何点击特定坐标?

时间:2013-12-24 22:02:02

标签: javascript jquery function click coordinates

我需要使用点击按钮后点击特定坐标的jQuery(或任何东西)。 specific coordinates

这是我的代码,但它不起作用。正如你在图片中看到的那样,这些坐标(10,15)是红色按钮,应点击它。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script>
    $(function(){
        $("#filter").click(function(e){
             //If I add alert here It successfully print message.
             var e = new jQuery.Event("click");
                e.pageX = 10;
                e.pageY = 15;
                $("#elem").trigger(e);
        });
    });
    </script>

<input type="button" id="filter" name="filter" value="Filter" />

我已经读过这篇文章了,但不会帮忙:Triggering a JavaScript click() event at specific coordinates

1 个答案:

答案 0 :(得分:1)

您基本上要做的是trigger click on some other buttonbased on the click of this button

你应该尝试这样的事情

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script>
    $(function(){
        $("#filter").click(function(e){
           $('#redbuttonID').trigger('click');
        });
    });
    </script>

不需要用于设置e.pageX等的其余代码

请参阅:http://jsfiddle.net/J9v6z/

编辑:

你可以使用x / y坐标得到一个元素 - 所以你可以在x / y上触发元素上的click事件。

$(document.elementFromPoint(x, y)).click();

$(document.elementFromPoint(x, y)).trigger('click');

https://developer.mozilla.org/En/DOM:document.elementFromPoint

编辑:更新了你的要求:

http://jsfiddle.net/J9v6z/1/

相关问题