右键点击Div [英] Right Click On Div
本文介绍了右键点击Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
有人可以帮我找出如何捕获
Hi All,
Could somebody please help me find out how to have a right click event captured for the
标签的右键单击事件.
可以说,我有一个名为function1()的函数,我想在div标签上单击鼠标右键.
有什么办法吗?
可以说,我有一个名为function1()的函数,我想在div标签上单击鼠标右键.
有什么办法吗?
tag.
Lets say, I have a function named function1(), which i want to call on the right click on the div tag.
Is there any way out?
Lets say, I have a function named function1(), which i want to call on the right click on the div tag.
Is there any way out?
推荐答案
看看这个:^ ].
鼠标右键的值为2,但是请注意,建议使用mousedown
或mouseup
事件而不是单击.
这是显示右键单击检测页面的示例:
Take a look at this: Javascript - Event properties[^].
Value for right mouse button is 2, although note that it recommends usingmousedown
ormouseup
events rather than click.
Here is a sample from the page showing right click detection:
function doSomething(e) {
var rightclick;
if (!e) var e = window.event;
if (e.which) rightclick = (e.which == 3);
else if (e.button) rightclick = (e.button == 2);
alert('Rightclick: ' + rightclick); // true or false
}
将这样的方法附加到div并代替警报,调用您的function1()
Attach method like this to div and inplace of alert call your function1()
这篇关于右键点击Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文