jQuery 在上下文菜单 Web 表单上

jQuery on Context Menu Web Forms

对 jQuery 很陌生,我正在尝试将右键单击菜单添加到 div id = "category" 经过多次谷歌搜索,我想出了这个,但没有用:

HTML:

 <div id ="category">
    <span class="categoryheading">
        <span id="catHide<%#Category %>" class="hidecategory" onclick="$('.cat<%#Category %>').hide(); $('#catHide<%#Category %>').hide(); $('#catShow<%#Category %>').show();">
        </span>
      <span id="catShow<%#Category %>" style="display: none;" class="showcategory" onclick="$('.cat<%#Category %>').show();  $('#catShow<%#Category %>').hide(); $('#catHide<%#Category %>').show();">
        </span>
    <%#Eval("GroupName").ToString() != "" ? Eval("GroupName") : "No Category" %>
   </span>
</div>

JQuery

  // Allow context menu on Category
        $("#category").contextMenu({
            items: {
                ExpandAll:{
                    name: "collapse",
                    title: "Collapse All",
                    alert: ("Test - It Works!!")},
                CollapseAll:{
                    name: "expand", 
                    title: "Expand All",
                    alert: ("Test - It works")}
            }
        });

非常感谢任何关于我哪里出错的指示。

您可以使用 JQuery-contextify 实现上下文菜单。

代码:

HTML :

<div id="menu">
  Hello
</div>

Javascript :

var options = {items:[
  {header: 'Options'},
  {text: 'First Link', href: '#'},
  {text: 'Second Link', onclick: function() {}},
  {divider: true},
  {text: 'Stuff', href: '#'}
]}
$('#menu').contextify(options);