您好,登錄后才能下訂單哦!
廢話不多說了,具體代碼如下所示:
<link rel="stylesheet" href="${ctx}/res/js/ztree/css/demo.css" type="text/css"/> <link rel="stylesheet" href="${ctx}/res/js/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/> <script type="text/javascript" src="${ctx}/res/js/ztree/js/jquery.ztree.core-3.5.js"></script>
<input onclick="showMenu();return false;"/>
var setting = { view: { dblClickExpand: false }, data: { simpleData: { enable: true } }, callback: { onClick: onClick } }; function onClick(e, treeId, treeNode) { var zTree = $.fn.zTree.getZTreeObj("treeDemo"), nodes = zTree.getSelectedNodes(); menuName = ""; menuId = ""; nodes.sort(function compare(a,b){return a.id-b.id;}); var isParent = nodes[0].getParentNode(); var isChildren = nodes[0].children; if((!isParent && !isChildren) || (isParent)){ for (var i=0, l=nodes.length; i<l; i++) { menuName += nodes[i].name + ","; menuId += nodes[i].id + ","; } if (menuName.length > 0 ) menuName = menuName.substring(0, menuName.length-1); if (menuId.length > 0 ) menuId = menuId.substring(0, menuId.length-1); $("#menuName").val(menuName); $("#menuId").val(menuId); } } function showMenu() { var cityObj = $("#menuName"); var cityOffset = $("#menuName").offset(); $("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast") $("body").bind("mousedown", onBodyDown); var width = cityObj.css("width"); $("#treeDemo").css("width",parseInt(width)-5); } function hideMenu() { $("#menuContent").fadeOut("fast"); $("body").unbind("mousedown", onBodyDown); } function onBodyDown(event) { if (!(event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) { hideMenu(); } } $(document).ready(function(){ $.fn.zTree.init($("#treeDemo"), setting, zNodes); });
以上所述是小編給大家介紹的jQuery中ztree 點擊文本框彈出下拉框的實例代碼,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。