function renderNavList() { ChannelList.forEach(function(val,index){ $(".header_menu_left").innerHTML+=`
  • ${val.title}
  • ` }); BindClickLi() } function BindClickLi() { var li = document.querySelectorAll(".header_menu_left li"); li.forEach((val,index)=> { val.onclick = function () { li.forEach(vas=>vas.className = ""); val.className = "active"; getData(ChannelList[index].type) }; }) } function getData(type) { http({ method: 'GET', url: 'http://127.0.0.1/mcf/news.php', data: { type: type }, success: function(res) { RenderPage(res.result.data) console.log(res.result.data) }, error: function(err) { } }); } function RenderPage(data) { $(".list_item").innerHTML = "" data.forEach((val,index)=> { if (val.hasOwnProperty("thumbnail_pic_s03") || val.hasOwnProperty("thumbnail_pic_s02")){ $(".list_item").innerHTML += `
  • ${val.title}

    ${val.author_name} ${val.category} ${val.date}
  • ` } else if (Math.random() > 0.5){ $(".list_item").innerHTML += `
  • ${val.title}

    ${val.title}
    ${val.author_name} ${val.date} ${val.category}
  • ` } else { $(".list_item").innerHTML += `
  • ${val.title}

    ${val.author_name} ${val.date} ${val.category}
    ${val.title}
  • ` } }) } getData('top') renderNavList() function $(className){ return document.querySelector(className) }