jquery上下文菜单禁用菜单项

前端之家收集整理的这篇文章主要介绍了jquery上下文菜单禁用菜单项前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
对于我的asp.net mvc 3应用程序,我正在使用 this plugin.但是我有一个问题,我想在创建菜单后启用或禁用某些菜单项,如:
<script type="text/javascript">
    $(function(){
        /**************************************************
         * Menu 1
         **************************************************/
        $.contextMenu({selector: '.context-menu-one',items: {
            edit: {name: "Edit",icon: "edit",callback: $.noop,accesskey:"e d i t"},cut: {name: "Cut",icon: "cut",accesskey:"c u t"},copy: {name: "Copy",icon: "copy",accesskey:"c o p y"},paste: {name: "Paste",icon: "paste",accesskey:"p a s t e"},"delete": {name: "Delete",icon: "delete",accesskey:"d e l t"},sep1: "---------",quit: {name: "Quit",icon: "quit",accesskey:"q u i t"}
        }});

        //not working
        $('.context-menu-one').contextMenu('commands[0].disabled','true');
      });

  </script>

不工作,任何想法?

解决方法

根据插件documentation,您可以指定要调用函数,以确定是否禁用了菜单项.

因此,您可以让该函数关闭局部变量,并更新该变量以启用或禁用这些项.就像是:

$(function() {
    var itemsDisabled = {};  // Enable everything initially.
    $.contextMenu({
        selector: ".context-menu-one",items: {
            // [...]
            cut: {
                name: "Cut",accesskey: "c u t",disabled: function(key,opt) {
                    return !!itemsDisabled[key];
                }
            }
            // [...]
        }
    });

    // Disable the "Cut" menu item.
    itemsDisabled["cut"] = true;
});
原文链接:https://www.f2er.com/jquery/176328.html

猜你在找的jQuery相关文章