juqery事件点击右键触发事件
程序员文章站
2022-06-11 17:14:04
...
<!DOCTYPE HTML>
<html>
<title>38</title>
<head>
<style>
div{
width:500px;
height:500px;
background-color:
#aabbcc;
}
</style>
<script src=
"http://code.jquery.com/jquery-latest.js"
></script>
</head>
<body>
<div></div>
<button>trigger</button>
</body>
<script>
$(
function
(){
$(
'div'
).mousedown(
function
(event, a){
if
(event.which == 1 || a ==
'left'
){
alert(
'left click'
);
}
if
(event.which == 3 || a ==
'right'
){
alert(
'right click'
);
}
});
$(
'button'
).click(
function
(){
$(
'div'
).trigger(
'mousedown'
, [
'right'
]);
});
});
</script>
</html>