我正在尝试使用此右键单击上下文菜单。它按预期工作,但是当我点击菜单项时,我不知道从哪里开始应用实际操作。显然现在所有它都说是后退菜单项被点击 - 目标ID ....,当有人点击它时,实际上会把他们带回一个页面副,只是说明他们点击了什么。
这是生成菜单的jquery
<script>
var callback = function(target,element){
$(target).html('<span style="color:red">' +$(element).html() +'</span> menu is clicked, Target id: '+ $(target).attr('id'));
};
var menu = {};
menu['back'] = {icon:'icon-arrow-left',text:'Back',click:callback};
menu['forward'] = {icon:'icon-arrow-right',text:'Forward',click:callback};
menu['view'] = {text:'View',click:callback};
menu['sortby'] = {text:'Sort by',click:callback};
menu['refresh'] = {icon:'icon-refresh',text:'Refresh',click:callback};
menu['notepad'] = {text:'Notepad++',click:callback};
menu['s1'] = '---';
menu['copy'] = {text:'Copy',click:callback};
menu['paste'] = {disabled:true,text:'Paste',click:callback};
menu['paste_shortcut'] = {disabled:true,text:'Paste shortcut',click:callback};
menu['s2'] = '---';
menu['create_shortcut'] = {text:'Create shortcut',click:callback};
menu['rename'] = {text:'Rename',click:callback};
menu['del'] = {text:'Delete',click:callback};
menu['s3'] = '---';
menu['properties'] = {text:'Properties',click:callback};
$('#id0').contextMenu(menu);
$('body').contextMenu(menu);
$('body').contextMenu('beforeDisplay',function(target){ console.log(target.html()) });
</script>
感谢您提供任何帮助/指导以及如何提前入门!
答案 0 :(得分:1)
替换
function(target){ console.log(target.html()) }
使用执行操作的功能。