我使用 jQuery UI 菜单作为上下文菜单,因此当用户单击表格中的单元格时,它会显示相关选项。问题是,它并不是真正设计为这样使用的,因此当用户单击菜单外部时它不会隐藏。
我尝试使用模糊方法:
$("#menu").menu({
blur: function( event, ui ) {
$("#menu").css('top', '-1000px');
$("#menu").css('left', '-1000px');
}
});
由于某种原因,即使您滚动到菜单中的某个选项,菜单也会隐藏。
有没有简单的解决方案?
编辑: 要拉出我使用的菜单:
$("table.adminScheduleViewer tr td:nth-child(4), table.adminScheduleViewer tr td:nth-child(5), table.adminScheduleViewer tr td:nth-child(6), table.adminScheduleViewer tr td:nth-child(7), table.adminScheduleViewer tr td:nth-child(8), table.adminScheduleViewer tr td:nth-child(9), table.adminScheduleViewer tr td:nth-child(10)").click(function(event){
$("#menu").css('top', event.pageY);
$("#menu").css('left', event.pageX);
});
如果我尝试使用 $('body').click() 隐藏它,它似乎总是首先被调用。你能改变 jQuery 处理点击的顺序吗?
最佳答案
$('body:not(#menu)').click(function(){
$("#menu").css({ 'top' : '-1000px', 'left' : '-1000px' });
});
我觉得这样比较性感
关于jquery - 当用户点击外部时隐藏 jQuery UI 菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15121098/