(function(){ var InfoData = JSON.parse(localStorage.getItem("info")); var LikeData = localStorage.getItem("like") == null ? [] : JSON.parse(localStorage.getItem("like")); var status = true; $(".info-header").css({ 'background': `url(${InfoData.albums[0]}) no-repeat center center`, 'background-size': 'cover' }) $('.info-title h3').text(InfoData.title) $('.info-title p').text(InfoData.tags) $('.item1 p').text(InfoData.ingredients) $('.item2 p').text(InfoData.burden) InfoData.steps.forEach((val,index) => { $('.list-item ul').append(`
  • ${index == 0 ? InfoData.title+'步骤'+(index+1) : '步骤'+(index+1)}

    ${val.step}

  • `) }); $("#likefood").on('click', function () { changeStatus() if(status) { LikeData.push(JSON.parse(localStorage.getItem("info"))) localStorage.setItem("like", JSON.stringify(LikeData)) $("#likefood").removeClass("icon-star-outline").addClass("icon-star") } else { YDUI.dialog.toast('您已经收藏过了', 'error', 1000); } }); function checkIsLike() { changeStatus() if(!status) { $("#likefood").removeClass("icon-star-outline").addClass("icon-star") } } function changeStatus () { LikeData.forEach( val => val.id == InfoData.id ? status = false : status = true); } checkIsLike() })()