右键单击坐标 [英] Right click coordinates
本文介绍了右键单击坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,我正在使用这个函数来获取XY坐标
Well, I'm using this function to get me the X Y coordinates
<input type="image" src="image.jpeg" name="foo" ondblclick="dclick()" onclick="lclick()" style="cursor:crosshair" value=""/>
$(document).ready(function() {
$('image').click(function(e) {
var offset = $(this).offset();
alert(e.clientX - offset.left);
alert(e.clientY - offset.top);
});
});
我的问题是这(显然)只能用鼠标左键单击...我怎么能适应右键点击?
My problem is that this (obviously) only work with the left mouse click... how can I adapt it to the right click?
推荐答案
尝试:
$('.image').on('contextmenu', function (e) {
console.log(e.pageX),
console.log(e.pageY);
});
上下文菜单是右键单击的事件。请注意,在选择器中的文本之前需要'。'或'#',或者如果您希望它应用于所有图像标记,则$('img')...
如果您需要要探索事件中的内容,只需使用console.log(e)浏览您可以从事件中获取的内容。
Context menu is the event for right click. Notice that you need either a '.' or a '#' before the text in the selector, or if you want it to apply to all image tags, then $('img')... If you want to explore what's in an event, just use console.log(e) to have a browse around what you can garner from an event.
这篇关于右键单击坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文