easyui和zTree分别实现树型下拉框
来源:互联网 发布:淘宝上的电子烟可靠吗 编辑:程序博客网 时间:2024/05/22 00:18
最近工作中需要用到树型下拉框,因为项目中树形结构使用的是zTree,然后就百度,结果出来效果不好看,后来就试着用了easyui的comboTree,虽然比较好看,但是跟整体的bootstrap风格有点儿不搭。现在贴出来两种方式及效果,以后备用。
方式一,使用zTree
前端代码:
<div class="form-group"> <label>点击事件:</label> <input id="selectActionType" class="form-control" onfocus="showActionTypeTree()" onclick="showActionTypeTree()" readonly="readonly" style="border-radius:5px;background-color: white;cursor: default;"/> <input type="hidden" name="actionTypeId" id="actionTypeId"/> <div id="actionTreeContent" class="menuContent" style="border-radius:5px;display: none; z-index:9999;position: absolute; border: 1px #CCC solid; background-color:#f9f9f9;"> <ul id="actionTypeTree" class="ztree" style="margin-top:0;height: 200px;overflow: auto"></ul> </div></div>
js代码:
/* * 点击事件下拉树的设置 */ var actionTypeSetting = { view: { dblClickExpand: true, showIcon: false, fontCss : {"font-weight":"400","font-size":"20px"} }, data: { key: { name: "text", children: "children" }, simpleData: { enable: true } }, callback: { onClick: actionTypeOnClick } }; /* * 点击事件下拉树的点击事件 */ function actionTypeOnClick(e, treeId, treeNode) { $("#actionTypeId").val(treeNode.id); $("#selectActionType").val(treeNode.text); } /* * 初始化点击事件类型 * */ function initActionType() { $.ajax({ async: false, cache: false, type: 'POST', dataType: "json", url: localStorage.getItem("adminPath") + '/touch/typeTable/getActionList?businessTypeId=2', error: function () {//请求失败处理函数 alert('请求失败'); }, success: function (data) { //请求成功后处理函数 $.fn.zTree.init($("#actionTypeTree"), actionTypeSetting, data); } }); } /* * 展示点击事件SelectTree */ function showActionTypeTree() { $.ajax({ url: localStorage.getItem("adminPath") + '/touch/typeTable/getActionList?businessTypeId=2', type: 'POST', dataType: "json", async: false, success: function (data) { $.fn.zTree.init($("#actionTypeTree"), actionTypeSetting, data); var deptObj = $("#selectActionType"); var deptOffset = $("#selectActionType").offset(); $("#actionTreeContent").css({ left: deptOffset.left - 26 + "px", top: deptOffset.top + "px" }).slideDown("fast"); $('#actionTypeTree').css({width: deptObj.outerWidth() + "px"}); var zTree = $.fn.zTree.getZTreeObj("actionTypeTree"); var node = zTree.getNodeByParam("id", $('#actionTypeId').val(), null); zTree.selectNode(node); $("body").bind("mousedown", onBodyDownByActionType); } }); } /* * Body鼠标按下事件回调函数 */ function onBodyDownByActionType(event) { if (event.target.id.indexOf('switch') == -1) { hideActionTypeMenu(); } } /* * 隐藏点击事件Tree */ function hideActionTypeMenu() { $("#actionTreeContent").fadeOut("fast"); $("body").unbind("mousedown", onBodyDownByActionType); }
方式二:使用easyui
前端代码:
<div class="form-group"> <label>点击事件:</label> <input id="actionTypeId2" name="actionTypeId2" class="form-control" /></div>js代码:
$("#actionTypeId2").combotree({ url: localStorage.getItem("adminPath") + '/touch/typeTable/getActionList?businessTypeId=2', textField:'name', onClick: function (node) { $("#actionTypeId").val(node.id); }, onSelect: function (node) { /** * 当选中该节点时展开该节点,同时关闭其他节点 */ if (node.state == "closed") { $(this).tree('expand', node.target); } else { var isLeaf = $(this).tree('isLeaf', node.target); if (!isLeaf) { $(this).tree("collapse", node.target); } } }});
阅读全文
0 0
- easyui和zTree分别实现树型下拉框
- jQuery和zTree实现的下拉树
- ztree实现下拉树展示
- Query+ztree实现下拉树复选框功能
- 使用zTree实现树形下拉框
- JQuery和ASP.NET分别实现级联下拉框效果
- easyui 下拉框树
- ztree下拉树
- 6.easyui+ztree案例:zTree树
- ztree实现下拉功能 input
- jquery ztree实现下拉树形框,json数据
- 分别用自定义PopupWindow和自定义Dialog实现下拉菜单
- easyui实现简单的下拉框
- easyui 下拉选择树(ComboTree) 的实现
- EasyUI实现下拉框多选
- easyUI下拉框表格扩展(实现搜索功能)[easyUI+java]
- easyui tree 实现类似ztree的数据格式
- easyUI&ztree
- easyui select 动态添加 option
- W3C盒模型与IE盒模型
- Java邮件开发(一):使用JMail发送一封简单邮件
- 使用GET,POST请求获取结果
- appium工作原理
- easyui和zTree分别实现树型下拉框
- 操作符函数及重载(4)
- Eclipse的android工程修改目标设备
- spark livy
- Android侧滑菜单
- HTML 导入导出
- OpenCV学习之Hough变换检测直线
- spring 配置多数据源
- Python-起源