可能重复:
如何用 jQuery 区分鼠标左键和右键
当我在 div 内单击鼠标右键时如何打开上下文菜单。因为当我在 div 内用鼠标右键单击时,它的淡出?
Javascript
$("#link").click(function(e){
e.stopPropagation();
div = $("#mydiv").fadeToggle(300);
});
$("#mydiv").click(function(e){
e.stopPropagation();
});
$(document).click(function(e){
$('#mydiv').fadeOut(200);
});
HTML
<a id="link">Click</a>
<div id="mydiv" style="width: 200px; height: 200px;">Hello</div>
更新:
Javascript
$("#link").click(function(e){
e.stopPropagation();
div = $("#mydiv").fadeToggle(300);
});
$("#good_buttom").click(function(e){
e.stopPropagation();
div = $("#hide").fadeToggle(300);
});
$("#mydiv").mousedown(function(e) {
switch (e.which) {
case 1:
e.stopPropagation();
$('#mydiv').fadeOut(200);
break;
case 2:
alert('2');
break;
case 3:
alert('3');
break;
default:
alert('You have a strange mouse');
}
});
HTML
<a id="link">Click</a>
<div id="mydiv" style="width: 200px; height: 200px;">
<button id="good_button">Click IT</button>
<div id="hide" style="display:none;">Show up.</div>
</div>