Javascript 将实际操作应用于右键单击关联菜单
我正在尝试使用这个右键单击上下文菜单。它的视觉效果与预期一样,但我不知道在单击菜单项时从何处开始应用实际操作。很明显,现在它所说的只是后退菜单项被点击了-目标id…,很明显,当有人点击后退时,它实际上会让他们返回一个页面,说明他们点击了什么 下面是生成菜单的jqueryJavascript 将实际操作应用于右键单击关联菜单,javascript,jquery,contextmenu,Javascript,Jquery,Contextmenu,我正在尝试使用这个右键单击上下文菜单。它的视觉效果与预期一样,但我不知道在单击菜单项时从何处开始应用实际操作。很明显,现在它所说的只是后退菜单项被点击了-目标id…,很明显,当有人点击后退时,它实际上会让他们返回一个页面,说明他们点击了什么 下面是生成菜单的jquery <script> var callback = function(target,element){ $(target).html('<span style="color:red">
<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>
var callback=函数(目标,元素){
$(target).html('+$(element).html()+'菜单被单击,目标id:'+$(target).attr('id'));
};
var菜单={};
菜单['back']={图标:'icon-arrow-left',文本:'back',点击:回调};
菜单['forward']={图标:'icon-arrow-right',文本:'forward',点击:回调};
菜单['view']={文本:'view',单击:回调};
菜单['sortby']={文本:'Sort by',单击:callback};
菜单['refresh']={图标:'icon-refresh',文本:'refresh',点击:回调};
菜单['notepad']={文本:'notepad++',单击:回调};
菜单['s1']='--';
菜单['copy']={文本:'copy',点击:回调};
菜单['paste']={禁用:true,文本:'paste',单击:回调};
菜单['paste_shortcut']={禁用:true,文本:'paste shortcut',单击:回调};
菜单['s2']='--';
菜单['create_shortcut']={文本:'create shortcut',单击:回调};
菜单['rename']={文本:'rename',单击:回调};
菜单['del']={文本:'Delete',单击:callback};
菜单['s3']='--';
菜单['properties']={文本:'properties',单击:回调};
$('#id0')。上下文菜单(菜单);
$('body')。上下文菜单(menu);
$('body').contextMenu('beforeDisplay',函数(目标){console.log(target.html())});
感谢您提供的任何帮助/指导,您可以在何处查看或如何提前开始 更换
function(target){ console.log(target.html()) }
具有执行操作的功能。替换
function(target){ console.log(target.html()) }
具有执行您的操作的函数。我想我应该更具体一些。如果我想要第一个选项,返回以使浏览器返回,我将用什么替换该行以使其返回。听起来这是一个不同的问题。如果你还有其他问题,你应该把它作为一个新问题发布——否则问题就会变成对话——我想我应该更具体一些。如果我想要第一个选项,返回以使浏览器返回,我将用什么替换该行以使其返回。听起来这是一个不同的问题。如果你有其他问题,你应该把它作为一个新问题发布——否则问题会变成对话——请参阅插件文档的帖子链接。有许多上下文菜单pluginPost链接到插件文档。有许多上下文菜单插件