Javascript 检测鼠标点击位置
我试图实现的是制作一个DIV并在其上显示世界地图图像或作为背景..&当用户单击地图上的某个位置时,我捕捉到鼠标单击的位置 接下来,我将介绍如何将鼠标的X、Y坐标转换为经度、纬度,然后运行AJAX来显示一些数据 我的问题是:Javascript 检测鼠标点击位置,javascript,html,events,mouseevent,Javascript,Html,Events,Mouseevent,我试图实现的是制作一个DIV并在其上显示世界地图图像或作为背景..&当用户单击地图上的某个位置时,我捕捉到鼠标单击的位置 接下来,我将介绍如何将鼠标的X、Y坐标转换为经度、纬度,然后运行AJAX来显示一些数据 我的问题是: 如何使用JavaScript获取鼠标单击位置 如何将全局单击位置转换为DIV的层的相对X,Y坐标 看看这个例子: 以下帖子也可能有所帮助: 在HTML中设置MouseMove事件: <div onMouseMove="getPositions();" st
- 如何使用JavaScript获取鼠标单击位置
- 如何将全局单击位置转换为DIV的层的相对X,Y坐标
- 看看这个例子:
<div onMouseMove="getPositions();"
style="width:200px;height:100px"></div>
除非你有理由从头开始做,否则我建议你
您会注意到该对象有一个click事件,您可以将接收包含lat/long坐标的MouseEvent的回调绑定到该事件。签出。在事件处理程序中,您可以通过mouseEvent参数获取它 摘自-
function getPositions(ev) {
if (ev == null) { ev = window.event }
_mouseX = ev.clientX;
_mouseY = ev.clientY;
}
function onMouseLeftButtonUp(sender, mouseEventArgs)
{
// Return a Point object representing the x- and y-coordinates of the current mouse position
// relative to the reference object.
var pt = mouseEventArgs.getPosition(sender.findName("referenceObject"));
// Display the current mouse position.
sender.findName("Status").text = pt.x + " : " + pt.y;
}