class Search { constructor() { footer() this.getSearch() this.seek() } async seek(newKey) { var res = await indexService.search({ keyword: newKey, page: 1 }); item($(".recommend .list"), res) } hidden (){ $(".suggest").style.display = "none" $(".recommend").style.display = "block" } show (){ $(".suggest").style.display = "block" $(".recommend").style.display = "none" } async getSearch() { var res = await indexService.search({ keyword: "长裙", page: 1 }); res.forEach(v => { $(".suggest_list").innerHTML += `
  • ${v.biaoqianlist[0].name}
  • ` }); // item($(".recommend .list"), res) //获取输入框值 $(".search_box").oninput = () => { if ($(".search_box").value.length > 0) { this.seek($(".search_box").value) } } //input获得焦点 $(".search_box").onfocus = () => { this.show() } $(".content").onclick = () => { this.hidden() } //标签绑定点击事件 click(".suggest_list li", (v, i) => { $(".search_box").value = v.innerText this.seek($(".search_box").value) this.hidden() }) //绑定搜索按钮 click(".icon-search", async (v, i) => { this.seek($(".search_box").value) this.hidden() }) click(".icon-back1", () => { history.back() }) } } new Search()