使用中键单击触发onclick事件 [英] Triggering onclick event using middle click
本文介绍了使用中键单击触发onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用散列链接的 onclick
事件打开< div>
作为弹出窗口。但中间点击不会触发 onclick
事件,但只接受 href
属性值链接并在新页面中加载URL。如何使用中间点击打开< div>
作为弹出窗口?
I am using the onclick
event of a hashed link to open a <div>
as a pop up. But the middle click does not trigger the onclick
event but only takes the href
attribute value of the link and loads the URL in a new page. How can I use middle click to open the <div>
as a popup?
推荐答案
beggs'的回答是正确的,但听起来你想要阻止中间点击的默认动作。在这种情况下,包括以下
beggs' answer is correct, but it sounds like you want to prevent the default action of the middle click. In which case, include the following
$("#foo").on('click', function(e) {
if( e.which == 2 ) {
e.preventDefault();
alert("middle button");
}
});
preventDefault()将停止事件的默认操作。
preventDefault() will stop the default action of the event.
这篇关于使用中键单击触发onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文