$(function () { $(".header_root").load("./comm/header.html"); $(".footer_root").load("./comm/footer.html"); // nav传值显示下划线 $(".header_root").data("nav_info", 5); // 新闻资讯搜索信息 let newsInfo = { page: 1, size: 9, newstitle: "", total: 0, }; // 加载新闻资讯列表 function loadNewsList(params) { let newsItemHtml = ""; $.each(params.list, function (newsIndex, newsItem) { newsItemHtml = '
' + newsItem.newstitle + '
' + $.msToDateString(newsItem.createtime * 1000) + "
"; }); $(".news_list_box").html(newsItemHtml); } // 加载新闻资讯页码 function loadNewsPages(params) { newsInfo.total = params.total || 0; let newsPageHtml = ""; for (let _page = 0; _page < Math.ceil(params.total / 9); _page++) { newsPageHtml += '
' + (_page + 1) + '
'; } $(".news_page_box").html(newsPageHtml); } // 搜索新闻列表 function searchList() { let _url = $.baseUrl + "n/listc"; $.ajax({ type: "POST", url: _url, dataType: "json", contentType: "application/json; charset=utf-8", data: JSON.stringify({ page: newsInfo.page, size: newsInfo.size, newstitle: newsInfo.newstitle, }), success: function (data) { if (data.code === 0) { loadNewsList(data.obj); loadNewsPages(data.obj); } else { alert(data.msg); } }, }); } // 回车搜索 function enterSearch(event) { // 兼容FF和IE和Opera let theEvent = event || window.event; let code = theEvent.keyCode || theEvent.which || theEvent.charCode; let content = theEvent.target.value; newsInfo.newstitle = content; if (code == 13) { searchList(); } } // 输入内容改变 function searchInputChange(event) { let theEvent = event || window.event; newsInfo.newstitle = theEvent.target.value; } $(".news_info #search_help").on("change", searchInputChange); $(".news_info #search_help").on("keydown", enterSearch); $(".news_info .search_box").click(searchList); searchList(); });