请问jquery怎么模拟右键单击?

mingfish 2009-12-24 11:43:17
不是键盘上的右键菜单按钮,而是鼠标上的右键 按钮,比如单击

<button>右键出来</button>

就相当于鼠标右键单击了一次,请问怎么做?
...全文
182 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
千游 2009-12-24
  • 打赏
  • 举报
回复
document.getElementById("button").onmouseup=function(oEvent) {
if (!oEvent) oEvent=window.event;
if (oEvent.button==2) {
// alert("右键单击");
}
}
wangyuehong516 2009-12-24
  • 打赏
  • 举报
回复
关注中...................
x_gh_java 2009-12-24
  • 打赏
  • 举报
回复
用鼠标放在button上,然后单击鼠标右键
das_jack 2009-12-24
  • 打赏
  • 举报
回复
/**!
*samples to simulate the right button down
*
*@$('.log_panel') is the target whose mousedown event will be simulated
*@$('.rect_box') is the parent of test button
*@myevent is the event object passed by ourself
*
**/
$('.log_panel').mousedown(function(event,myevent){

log('log_panel mouse down');

if(!myevent){
myevent = event;
}

log('mouse event:'+ myevent.which+' pos='+ myevent.pageX+','+ myevent.pageY);
});

//create the button
$('<button id="test_bt" value="right_click">right_click</button>').appendTo($('.rect_box'))
.click(function(event){

//change the mousedown type as right button down
event.which = 3;

log('simulate right button down');
//pass this event as params
$('.log_panel').trigger('mousedown',[event]);
});

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧