Easy to achieve pull-down tree

Recent need a text box drop-down tree, with the idea of ​​the spirit of the Internet just to find a use, first meal fierce on the Internet to find, download the code three or four, not a nice result.

Or it is too simple, or is too complicated to achieve, can not get their own, because zTree used before, here the zTree slightly modified look, take a little time, basically also be used.

FIG achieve the effect:

The main idea:

When you click the text box to display the hidden layer Div, Div layer contains a tree control when other parts of the page, click, Div hidden layer, while the value is written to the selected text box.

Page code is as follows:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="WebApp.Views.OrderManage.Test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="../../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<link href="../../Content/themes/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/ztree/jquery.ztree.core-3.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/ztree/jquery.ztree.excheck-3.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
        <!--
    var setting = {
        view: {
            showIcon: false
        },
        data: {         
            simpleData: {
                enable: true
            }
        },
        callback: {            
            onClick: onClick
        }
    };
    
    function onClick(e, treeId, treeNode) {        
        $('#txtTreeSelect').val(treeNode.name);
    }

    function showMenu() {
        var cityObj = $('#txtTreeSelect'); 
        var cityOffset = cityObj.offset();
        $("#menuContent").css({ left: cityOffset.left + "px", top: cityOffset.top + cityObj.outerHeight() + "px" }).slideDown("fast");
        $("body").bind("mousedown", onBodyDown);
    }

    function hideMenu() {
        $("#menuContent").fadeOut("fast");
        $("body").unbind("mousedown", onBodyDown);
    }
    function onBodyDown(event) {
        if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length > 0)) {
            hideMenu();
        }
    }

    $(document).ready(function () {
        varzNodes = [ 
            {name: " all " , Open: to true , 
                Children: [ 
                    {name: " unapproved " , 
                        Children: [ 
                            {name: " leaf node 111 " }, 
                            {name: " leaf node 112 " }, 
                            {name : " leaf node 113 " }, 
                            {name: " leaf node 114 " }
                        ]
                    },
                    {Name: " audited " , 
                        Children: [ 
                            {name: " leaf node 121 " }, 
                            {name: " leaf node 122 " }, 
                            {name: " leaf node 123 " }, 
                            {name: " leaf node 124 " } 
                        ] 
                    } 
                ] 
            } 
        ]; 
        $ .fn.zTree.init ($ ( "#treeDemo"), setting, zNodes);        
    });
        //-->
</script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="txtTreeSelect" type="text" onclick="showMenu(); return false;"/>
    </div>
<div id="menuContent" class="menuContent" style="display: none; position: absolute;">
    <ul id="treeDemo" class="ztree" style="margin-top: 0; width: 120px; height:80px;">
    </ul>
</div>
    </form>
</body>
</html>

 

Reproduced in: https: //www.cnblogs.com/ushou/p/3139873.html

Guess you like

Origin blog.csdn.net/weixin_34167043/article/details/93765197