[zTree]添加右键菜单

关键代码:

/// <reference path="zTree_v3-master/js/jquery-1.4.4.min.js" />
/// <reference path="zTree_v3-master/js/jquery.zTree.all-3.5.js" />
(function (window) {
    yzTreeUtils = {
        addMenu: function (zTreeId, menuId) {
            /// <summary>
            /// 增加右键菜单
            /// </summary>
            /// <param name="_zTreeId">_zTreeID</param>
            /// <param name="menuId">右键菜单ID</param>
            var _zTree = $.fn.zTree.getZTreeObj(zTreeId);
            var _rMenu = $("#" + menuId);
            if (_zTree && _rMenu) {
                _rMenu.css({
                    "position": "absolute",
                    "visibility": "hidden",
                    "top": 0,
                    "background-color": "#555",
                    "text-align": "left",
                    "padding": "2px"
                });
                _rMenu.find(‘ul‘).css({
                    "margin": "1px 0",
                    "padding": "0 5px",
                    "cursor": "pointer",
                    "background-color": " #DFDFDF",
                    "list-style": "none outside none"
                });
                _zTree.setting.callback.onRightClick = function (event, treeId, treeNode) {
                    if (treeNode && !treeNode.noR) {
                        _zTree.selectNode(treeNode);
                        _rMenu.find(‘ul‘).show();
                        var x = event.clientX, y = event.clientY;
                        _rMenu.css({ "top": y + "px", "left": x + "px", "visibility": "visible" });
                    }
                }
                $("body").bind("mousedown", function (event) {
                    if (!(event.target.id == menuId || $(event.target).parents("#" + menuId).length > 0)) {
                        _rMenu.css({ "visibility": "hidden" });
                    }
                });
            }
        }
    }
    window.yzTreeUtils = yzTreeUtils;
})(window);

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

示例:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <link href="ztree_v3-master/css/ztreestyle/ztreestyle.css" rel="stylesheet" />
    <link href="ztree_v3-master/css/demo.css" rel="stylesheet" />
    <script src="ztree_v3-master/js/jquery-1.4.4.min.js"></script>
    <script src="ztree_v3-master/js/jquery.ztree.core-3.5.js"></script>
    <script src="yzTreeUtils.js"></script>
    <script>
        var setting = {
            view: {
                dblClickExpand: false
            },
            check: {
                enable: true
            }
        };
        var zNodes = [
        {
            id: 1, name: "无右键菜单 1", open: true, noR: true,
            children: [
                   { id: 11, name: "节点 1-1", noR: true },
                   { id: 12, name: "节点 1-2", noR: true }
            ]
        },
        {
            id: 2, name: "右键操作 2", open: true,
            children: [
                   { id: 21, name: "节点 2-1" },
                   { id: 22, name: "节点 2-2" },
                   { id: 23, name: "节点 2-3" },
                   { id: 24, name: "节点 2-4" }
            ]
        },
        {
            id: 3, name: "右键操作 3", open: true,
            children: [
                   { id: 31, name: "节点 3-1" },
                   { id: 32, name: "节点 3-2" },
                   { id: 33, name: "节点 3-3" },
                   { id: 34, name: "节点 3-4" }
            ]
        }
        ];
        $(document).ready(function () {
            $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        });
        function addMenu() {
            yzTreeUtils.addMenu(‘treeDemo‘, ‘rMenu‘);
        }
    </script>
    <title></title>
</head>
<body>
    <div class="content_wrap">
        <div class="zTreeDemoBackground left">
            <ul id="treeDemo" class="ztree"></ul>
        </div>
    </div>
    <br />
    <input id="Button1" type="button" value="addMenu" onclick="addMenu()" />
    <div id="rMenu">
        <ul>
            <li id="m_add" onclick="addTreeNode();">增加节点</li>
            <li id="m_del" onclick="removeTreeNode();">删除节点</li>
            <li id="m_check" onclick="checkTreeNode(true);">Check节点</li>
            <li id="m_unCheck" onclick="checkTreeNode(false);">unCheck节点</li>
            <li id="m_reset" onclick="resetTree();">恢复zTree</li>
        </ul>
    </div>
</body>
</html>

注意黄色背景代码,效果:

希望有所帮助!谢谢!

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

时间: 2024-12-15 01:59:37

[zTree]添加右键菜单的相关文章

给jquery easy-ui 添加右键菜单

版权声明:转自为EasyUI 的Tab 标签添加右键菜单 1 <!doctype html> 2 <html> 3 <head> 4 <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 5 <title>tabs 右键菜单demo QQ:15129679</title> 6 <link rel="

添加右键菜单

有时我们安装绿色版的软件常常是没有右键菜单的,但是对于一些常用的软件,我们需要添加右键菜单,添加方法,打开记事本,复制以下内容,按照自己的需要修改下所在软件的路径将txt另存为bat格式,双击即可: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\PotPlayer] @="Open with PotPlayer" "Icon"="E:\\Program Files (x86)

Arcengine 二次开发添加右键菜单

最近在搞arcengine 二次开发,遇到了好多问题,也通过网上查资料试着慢慢解决了,把解决的步骤记录下来,有需要帮助的可以看一下,也欢迎各位来批评指正. 想给自己的map application在图层上添加右键菜单,谷歌了一下,找到了解决的方法,原文的地址edndoc.esri.com/arcobjects/9.2/NET/1ED14BF2-A0E3-4e56-A70D-B9A7F7EC7880.htm.然后我根据这个添加了自己的右键菜单,又有一些改动. 效果如图所示(有点简陋),仅仅是简单的

添加右键菜单命令 在此处打开命令窗口(W)(带图标)

@color 0A @title 添加右键菜单命令 在此处打开命令窗口(W)(带图标) by wjshan0808 @echo off reg add HKCR\Directory\Background\shell\在此处打开命令窗口(W) /v Icon /t reg_expand_sz /d %ComSpec% /f reg add HKCR\Directory\Background\shell\在此处打开命令窗口(W)\command /ve /t reg_sz /d "%ComSpec%

仅在TabControl中的Tab中添加右键菜单

若想实现仅在TabControl中的Tab中添加右键菜单,可在XAML中通过使用样式得到: <TabControl> <TabControl.ItemContainerStyle> <Style TargetType="{x:Type TabItem}"> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu/> <!--

dev gridcontrol添加右键菜单

概述:右键菜单肯定是GridView中经常要使用的一个功能.本文主要描述两个方面:如何在GridView中添加右键菜单,以及如何设置菜单是否可用(enable). 右键菜单肯定是gridview中经常要使用的一个功能.本文主要描述两个方面:如何在GridView中添加右键菜单,以及如何设置菜单是否可用(enable). 一.添加右键菜单 1.在VS工具箱中的“菜单和工具栏”找到ContextMenuStrip控件,双击添加. 2.点击ContextMenuStrip右上方的小三角形,打开编辑项,

在ListCtrl上添加右键菜单,并创建响应函数。

一:添加右键菜单(在选中的行上面添加右键响应菜单) 1.首先创建一个菜单资源,在该项目上右键,添加资源,菜单资源,新建一个菜单资源(不会显示顶级菜单,只显示次级菜单). 2.在自己新添加的类CMyListCtrl(该类继承自CListCtrl,并且该类类型的对象与ListCtrl资源进行了绑定),并在该类的消息中添加=NM_RCLICK消息,在它的消息处理函数中, 添加右键弹出菜单代码: CMenu menu; menu.LoadMenuW(IDR_MENU1); //加载菜单资源 CMenu*

DevExpress TreeList添加右键菜单问题

添加右键流程: 1.先在窗体上拖两个控件,分别是popupMenu和barManager 2.barManager中绑定form属性为当前窗体名称 3.点击barManager右键选择customize,可直接添加子菜单,如果需要有工具栏.菜单栏.状态栏.怎选择Designer,可添加,然后在选择customize,添加command命令,再command选中菜单中执行命令 4.绑定右键菜单事件:在MouseDown事件中处理事件 --------------------------------

[WinForm]TreeView 添加右键菜单

关机代码: #region 添加右键菜单 /// <summary> /// 添加右键菜单 /// <para>eg: treeF18.AttachMenu(contextMenuTree, n => n != null);</para> /// </summary> /// <param name="treeView">TreeView</param> /// <param name="co