您好,登錄后才能下訂單哦!
廢話不多說,直接上代碼吧!
<!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 href="layui/css/layui.css" rel="external nofollow" rel="stylesheet" /> <script src="layui/layui.js"></script> <!-- 注意:如果你直接復制所有代碼到本地,上述css路徑需要改成你本地的 --> </head> <body> <div class="layui-layout layui-layout-admin"> <div class="layui-header"> <div class="layui-logo">layui 后臺布局</div> <!-- 頭部區域(可配合layui已有的水平導航) --> <ul class="layui-nav layui-layout-left"> <li class="layui-nav-item"><a href="">控制臺</a></li> <li class="layui-nav-item"><a href="">商品管理</a></li> <li class="layui-nav-item"><a href="">用戶</a></li> <li class="layui-nav-item"> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >其它系統</a> <dl class="layui-nav-child"> <dd><a href="">郵件管理</a></dd> <dd><a href="">消息管理</a></dd> <dd><a href="">授權管理</a></dd> </dl> </li> </ul> <ul class="layui-nav layui-layout-right"> <li class="layui-nav-item"> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <img src="http://t.cn/RCzsdCq" class="layui-nav-img"> 賢心 </a> <dl class="layui-nav-child"> <dd><a href="">基本資料</a></dd> <dd><a href="">安全設置</a></dd> </dl> </li> <li class="layui-nav-item"><a href="">退了</a></li> </ul> </div> <div class="layui-side layui-bg-black"> <div class="layui-side-scroll"> <!-- 左側導航區域(可配合layui已有的垂直導航) --> <ul class="layui-nav layui-nav-tree" lay-filter="test"> <li class="layui-nav-item layui-nav-itemed"> <a class="" href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >所有商品</a> <dl class="layui-nav-child"> <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >列表一</a></dd> <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >列表二</a></dd> <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >列表三</a></dd> <dd><a href="">超鏈接</a></dd> </dl> </li> <li class="layui-nav-item"> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >解決方案</a> <dl class="layui-nav-child"> <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >列表一</a></dd> <dd><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >列表二</a></dd> <dd><a href="">超鏈接</a></dd> </dl> </li> <li class="layui-nav-item"><a href="">云市場</a></li> <li class="layui-nav-item"><a href="">發布商品</a></li> </ul> </div> </div> <div class="layui-body"> <div > <div class="layui-tab" lay-filter="demo" > <ul class="layui-tab-title" > <li class="layui-this" lay-id="11" id="11">網站設置 </li> <li lay-id="22">用戶管理 <i class="layui-icon layui-unselect layui-tab-close">ဆ</i></li> <li lay-id="33">權限分配</li> <li lay-id="44">商品管理</li> <li lay-id="55">訂單管理</li> </ul> <div class="layui-tab-content"> <div class="layui-tab-item layui-show">內容1</div> <div class="layui-tab-item">內容2</div> <div class="layui-tab-item">內容3</div> <div class="layui-tab-item">內容4</div> <div class="layui-tab-item">內容5</div> </div> </div> <div class="site-demo-button" > <button class="layui-btn site-demo-active" data-type="tabAdd">新增Tab項</button> <button class="layui-btn site-demo-active" data-type="tabDelete">刪除:商品管理</button> <button class="layui-btn site-demo-active" data-type="tabChange">切換到:用戶管理</button> </div> </div> </div> </div> <!-- 注意:如果你直接復制所有代碼到本地,上述js路徑需要改成你本地的 --> <script> layui.use('element', function () { var $ = layui.jquery , element = layui.element; //Tab的切換功能,切換事件監聽等,需要依賴element模塊 //觸發事件 var active = { tabAdd: function () { //新增一個Tab項 element.tabAdd('demo', { title: '新選項<i class="layui-icon layui-unselect layui-tab-close">ဆ</i>' //用于演示 , content: '內容' + (Math.random() * 1000 | 0) , id: new Date().getTime() //實際使用一般是規定好的id,這里以時間戳模擬下 }); //增加點擊關閉事件 var r = $(".layui-tab-title").find("li"); //每次新打開tab都是最后一個,所以只對最后一個tab添加點擊關閉事件 r.eq(r.length - 1).children("i").on("click", function () { alert($(this).parent("li").attr('lay-id')); element.tabDelete("demo", $(this).parent("li").attr('lay-id')); }), element.tabChange("demo", r.length - 1); element.init(); } , tabDelete: function (othis) { //刪除指定Tab項 element.tabDelete('demo', '44'); //刪除:“商品管理” othis.addClass('layui-btn-disabled'); } , tabChange: function () { //切換到指定Tab項 element.tabChange('demo', '22'); //切換到:用戶管理 } }; $('.site-demo-active').on('click', function () { var othis = $(this), type = othis.data('type'); active[type] ? active[type].call(this, othis) : ''; }); //Hash地址的定位 var layid = location.hash.replace(/^#test=/, ''); element.tabChange('test', layid); element.on('tab(test)', function (elem) { location.hash = 'test=' + $(this).attr('lay-id'); }); }); </script> </body> </html>
以上這篇layerui代碼控制tab選項卡,添加,關閉的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。