jquery - 在 jQuery 中使用鼠标位置设置单击事件

标签 jquery jquery-events

谁能告诉我如何将点击功能分配给元素内的特定坐标?

最佳答案

$(document).click(function(event) {
    var top = 0,
        right = 200,
        bottom = 200,
        left = 0;


    var x = event.pageX;
    var y = event.pageY;
    if ((x >= left && x <= right) && (y >= top && y <= bottom))
    {
        // do stuff if within the rectangle
    }
});

关于jquery - 在 jQuery 中使用鼠标位置设置单击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10580046/

相关文章:

asp.net-mvc - 更改表中给定行的背景颜色

javascript - 将输入转换为小写

javascript - 第一个事件处理程序覆盖第二个事件处理程序

当浏览器窗口的尺寸为 x 或 y 时,Javascript 会调整浏览器窗口的大小

javascript - 查找具有特定数据属性的元素 jQuery

javascript - 如何使用 javascript 回发到不同的表单

javascript - 如何通过两个嵌套的匿名函数传递变量(带有超时的事件处理程序)

javascript - 如何使用 Firebug 或类似工具调试 JavaScript/jQuery 事件绑定(bind)?

javascript - 根据元素数据工具提示值使用 JSON 填充工具提示

javascript - 是否可以为 jQuery 事件对象添加自定义属性?