[Ztree] Add right-click menu

Source: Internet
Author: User

Key code:

/// <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>            /// Add right-click menu            // </summary>            /// <param name= "_ztreeid" >_zTreeID</param>            /// <param name= "MenuId" > Right-click menu 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 ();varx =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);

Example:

<!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>varsetting = {view: {dblclickexpand:false}, check: {enable:true}        };varZnodes = [{id:1, Name:"No Right-click menu 1", open:true, NoR:true, children: [{id:11, Name:"Node 1-1", NoR:true}, {id:12, Name:"Node 1-2", NoR:true}]}, {id:2, Name:"Right-click Operation 2", open:true, children: [{id:21, Name:"Node 2-1"}, {id:22, Name:"Node 2-2"}, {id:23, Name:"Node 2-3"}, {id:24, Name:"Node 2-4"}]}, {id:3, Name:"Right-click Operation 3", open:true, children: [{id:31, Name:"Node 3-1"}, {id:32, Name:"Node 3-2"}, {id:33, Name:"Node 3-3"}, {id:34, Name:"Node 3-4"}            ]        }        ]; $ (document). Ready (function() {$.fn.ztree.init ($ ("#treeDemo"), setting, znodes); });functionAddMenu () {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 ();">Adding nodes</Li>            <Li ID= "M_del" onclick= "Removetreenode ();">Delete a node</Li>            <Li ID= "M_check" onclick= "Checktreenode (true);">Check node</Li>            <Li ID= "M_uncheck" onclick= "Checktreenode (false);">Uncheck node</Li>            <Li ID= "M_reset" onclick= "Resettree ();">Recovery Ztree</Li>        </ul>    </Div></Body></HTML>

Note The yellow background code, the effect:

Hope to be helpful! Thank you!

[Ztree] Add right-click menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.