<input>
与type="image"
和name="something"
会将变量something_x
和something_y
与点击图像的坐标一起发送到服务器。INPUT type = image,如何获得坐标值?
如果表单正在被JavaScript处理,例如在AJAX设置中,我该如何获取元素被点击的坐标?
到目前为止,我唯一的想法就是设置:
imginput.onclick = function(e) {
e = e || window.event;
var coords = getMouseCoords(e), elempos = getElementCoords(this); // defined elsewhere
this.value = (coords.x - elempos.x)+","+(coords.y - elempos.y);
}
的问题是,我必须确保onclick
事件被分配到正确的输入元素,即使它们被加载或以其他方式创建文档加载完成后(我在处理客户工具提示时不得不面对的一个问题)。有没有更好的解决方案?