layui添加动态菜单与选项卡_javascript技巧_脚本之家

本文实例为大家分享了layui添加动态菜单与选项卡的具体代码,供大家参考,具体内容如下

  Layui                    

layui.use { function checkLastItem { return arr.length == ; } function getAhtml{ return "" + obj.name + ""; } //动态菜单 layui.jquery.ajax({ url: "http://127.0.0.1:18000/sys/menus", method: 'POST', success: function { var html = ""; for(var i = 0; i < res.length; i++) { var strli = "

“; if { strli = strli + “” + res[i].name +
“”; console.log
}else{ strli = strli + getAhtml; } if(res[i].pId == “0” &&
!checkLastItem && res[i + 1].pId != “0”) { strli = strli + “

“; for(; !checkLastItem && res[i + 1].pId != “0”; i++) { strli = strli

“+getAhtml+”

“; } strli = strli + “

“; } strli = strli + “

“; html = html + strli; } layui.jquery; layui.element.init;
//添加选项卡function addTab { if(layui.jquery(“.layui-tab-title
li[lay-id='” + name + “‘]”).length > 0) { //选项卡已经存在
layui.element.tabChange; layer.msg } else { //动态控制iframe高度 var
tabheight = layui.jquery – 95; contentTxt = ‘

‘; //新增一个Tab项 layui.element.tabAdd(‘tabDemo’, { title: name,
content: contentTxt, id: name }) //切换刷新 layui.element.tabChange
layer.msg }}

[ { "name": "首页", "url": "shouye.html", "id": "1", "pId": "0" }, { "name": "数据库", "url": "#", "id": "1", "pId": "0" }, { "name": "MYSQL", "url": "mysql.html", "id": "2", "pId": "1" }, { "name": "ORACLE", "url": "oracle.html", "id": "3", "pId": "1" }, { "name": "开发语言", "url": "#", "id": "4", "pId": "0" }, { "name": "JAVA", "url": "java.html", "id": "5", "pId": "4" }, { "name": "Python", "url": "python.html", "id": "6", "pId": "4" }]

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图