//文件结构
var listInfo = [ { zTit: '网站首页', icon: './image/left.png', hicon: './image/down.png', xTit: [ { name: '关于我们', href:'./home.html', }, { name: '客户中心', href:'./home.html', }, { name: '新闻资讯', href:'./home.html', } ], }, { zTit: '网站首页', icon: './image/left.png', hicon: './image/down.png', xTit: [ { name: '关于我们', href:'./home.html', }, { name: '客户中心', href:'./home.html', }, { name: '新闻资讯', href:'./home.html', } ], }, ]
//用forEach方法遍历获取
listInfo.forEach((item, index) => {
selects.innerHTML +=
`
<li class="selects_list">
<a></a>
<div class="h_list_con">
<p>${item.zTit}</p>
<div class="icon">
<img class="sIcon" src="${item.icon}" alt="">
<img class="hIcon" style="display:none;" src="${item.hicon}" alt="">
</div>
</div>
<div class="h_list_hid">
${item.xTit.map((element, index) => {
return `<p><a href="${element.href}">${element.name}</a></p>`
}).join('')}
</div>
</li>
`
})