Layui tree 下拉菜单树

原文地址:https://www.cnblogs.com/yysbolg/p/8968992.html

1.效果:

2.html  代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="static/layui/css/layui.css" media="all">
    <!-- 注意:如果你直接复制所有代码到本地,上述css路径需要改成你本地的 -->
    <style type="text/css">
        .downpanel .layui-select-title span {
            line-height: 38px;
        }

        /*继承父类颜色*/
        .downpanel dl dd:hover {
            background-color: inherit;
        }
    </style>
    <style type="text/css">
        body {
            height: 100%;
            width: 100%;
            background-size: cover;
            margin: 0 auto;
        }
        td {
            font-size: 12px !important;
        }

        .layui-form-checkbox span {
            height: 30px;
        }
        .layui-field-title {
            border-top: 1px solid white;
        }
        table {
            width: 100% !important;
        }

    </style>

</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">文章栏目</label>
        <div class="layui-input-inline">
            <div class="layui-unselect layui-form-select downpanel">
                <div class="layui-select-title">
                    <span class="layui-input layui-unselect" id="treeclass">选择栏目</span>
                    <input type="hidden" name="selectID" value="0">
                    <i class="layui-edge"></i>
                </div>
                <dl class="layui-anim layui-anim-upbit">
                    <dd>
                        <ul id="classtree"></ul>
                    </dd>
                </dl>
            </div>
        </div>
    </div>
</form>

<script src="static/layui/layui.js" charset="utf-8"></script>
<!-- 注意:如果你直接复制所有代码到本地,上述js路径需要改成你本地的 -->
<script type="text/javascript">
    layui.use([‘element‘, ‘tree‘, ‘layer‘, ‘form‘, ‘upload‘], function () {
        var $ = layui.jquery, tree = layui.tree;
        tree({
            elem: "#classtree"
            ,
            nodes: [{
                name: ‘常用文件夹‘,
                id: 1,
                alias: ‘changyong‘,
                children: [{name: ‘所有未读‘, id: 11, href: ‘http://www.layui.com/‘, alias: ‘weidu‘}, {
                    name: ‘置顶邮件‘,
                    id: 12
                }, {name: ‘标签邮件‘, id: 13}]
            }, {
                name: ‘我的邮箱‘,
                id: 2,
                spread: true,
                children: [{
                    name: ‘QQ邮箱‘,
                    id: 21,
                    spread: true,
                    children: [{
                        name: ‘收件箱‘,
                        id: 211,
                        children: [{name: ‘所有未读‘, id: 2111}, {name: ‘置顶邮件‘, id: 2112}, {name: ‘标签邮件‘, id: 2113}]
                    }, {name: ‘已发出的邮件‘, id: 212}, {name: ‘垃圾邮件‘, id: 213}]
                }, {
                    name: ‘阿里云邮‘,
                    id: 22,
                    children: [{name: ‘收件箱‘, id: 221}, {name: ‘已发出的邮件‘, id: 222}, {name: ‘垃圾邮件‘, id: 223}]
                }]
            }]
            ,
            click: function (node) {
                var $select = $($(this)[0].elem).parents(".layui-form-select");
                $select.removeClass("layui-form-selected").find(".layui-select-title span").html(node.name).end().find("input:hidden[name=‘selectID‘]").val(node.id);
            }
        });
        $(".downpanel").on("click", ".layui-select-title", function (e) {
            $(".layui-form-select").not($(this).parents(".layui-form-select")).removeClass("layui-form-selected");
            $(this).parents(".downpanel").toggleClass("layui-form-selected");
            layui.stope(e);
        }).on("click", "dl i", function (e) {
            layui.stope(e);
        });
        $(document).on("click", function (e) {
            $(".layui-form-select").removeClass("layui-form-selected");
        });

    });
</script>
</body>
</html>
</body>
</html>

原文地址:https://www.cnblogs.com/cnblogs296/p/9208319.html

时间: 2024-10-18 14:10:29

Layui tree 下拉菜单树的相关文章

layui select下拉菜单联动

做的比较简单,先从后台直接把第一级菜单输出,然后点击二级菜单的时候再动态展示 <div class="layui-inline"> <label class="layui-form-label">商品类别</label> <div class="layui-input-inline"> <select name="interest" lay-filter="one

layui省市区下拉菜单三级联动

使用这个功能需要用到layui这个文件夹的内容,所以不能只把layui.css和layui.js引入,要从layui文件夹获取 显示效果 代码部分 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-

HTML+JS+CSS 实现下拉菜单

最近在看视频学习做一些HTML+JS+CSS的实例,第一个是实现下拉菜单. 5.7 制作的思路是:1.静态网页的制作 2.动态特效实现菜单的显示和隐藏(三种方法:css.JavaScript.jQuery) 3.浏览器的兼容问题(低版本IE可能不支持等) 在用css实现时,由于盒子模型有自己默认的margin和padding值,所以要reset. 有一点比较有疑问的实,老师在视频里说position:absolute要和left.top同时使用.这是为什么?在实现的时候,我并没有使用left和t

用HTML和CSS实现的下拉菜单

<!doctype html><html lang="en"> <head> <meta charset="UTF-8"> <title>用HTML和CSS实现下拉列表</title> <style> /*导航栏的样式*/ *{margin:0;padding:0;} #nav{background-color:#eee;width:500px;height:40px;margin:

boostrapt的二级下拉菜单

<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <meta content="yes" name="apple-mobile-web-app-capable"> <meta content="black" name="apple-mobile-web-app-status-bar-style&qu

Bootstrap下拉菜单

[Bootstrap 下拉菜单] <div class="dropdown"> <button type="button" class="btn dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown">主题 <span class="caret"></span> </but

bootstrap-按钮的向下向上三角形-向上弹起的下拉菜单

1.运行效果如图所示 2.实现代码如下 <!DOCTYPE html> <html> <head>     <meta charset="utf-8">     <meta http-equiv="X-UA-Compatible" content="IE=edge">     <title>按钮的向下向上三角形-向上弹起的下拉菜单</title>     <

bootstrap-导航加下拉菜单(二级导航)

1.运行效果如图所示 2.实现代码如下 <!DOCTYPE html> <html> <head>     <meta charset="utf-8">     <meta http-equiv="X-UA-Compatible" content="IE=edge">     <title>导航加下拉菜单(二级导航)</title>     <!-- 最新版

bootstrap(4)关于下拉菜单的功能

一:下拉菜单: 下拉菜单的代码实现: <div class="dropdown"> <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="