layui添加动态菜单与选项卡AJAX请求的例子
如下所示:
创新互联专注为客户提供全方位的互联网综合服务,包含不限于网站建设、网站设计、阆中网络推广、成都微信小程序、阆中网络营销、阆中企业策划、阆中品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供阆中建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com
HTML
Layui
index.js
layui.use('element', function() { function checkLastItem(arr, i) { return arr.length == (i + 1); } function getAhtml(obj){ return "" + obj.name + ""; } //动态菜单 layui.jquery.ajax({ url: "http://127.0.0.1:18000/sys/menus", method: 'POST', success: function(res) { var html = ""; for(var i = 0; i < res.length; i++) { var strli = "
- ";
for(; !checkLastItem(res, i) && res[i + 1].pId != "0"; i++) {
strli = strli + "
- "+getAhtml(res[i+1])+" "; } strli = strli + "
菜单JSON
[ { "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" } ]
效果截图
以上这篇layui添加动态菜单与选项卡 AJAX请求的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持创新互联。
网站题目:layui添加动态菜单与选项卡AJAX请求的例子
文章出自:http://ybzwz.com/article/ggppjo.html