index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. $(function () {
  2. var enterprisedynamic = '/nx/article/enterprisedynamic';//企业宣传
  3. var industrynews = '/nx/article/industrynews'; //行业动态
  4. var policies = '/nx/article/policies'; //政策法规
  5. var url = enterprisedynamic;
  6. var getNews = function (url, p) {
  7. p = p || 1;
  8. $.ajax({
  9. url: getServerHttp('cp') + url,
  10. type: 'post',
  11. cache: false,
  12. dataType: 'json',
  13. data: {
  14. p: p
  15. },
  16. success: function (data) {
  17. var data = ajaxDataParames(data);
  18. var dom = '';
  19. for (var i = 0; i < data.rows.length; i++) {
  20. var _href = './component/news.html?kid=' + data.rows[i].kid;
  21. dom += '<li><a href="' + _href + '" target="_blank" title="' + data.rows[i].title + '">' + data.rows[i].title + '<span>' + data.rows[i].date + '</span></a></li>'
  22. }
  23. $('.lists ul').html(dom);
  24. layui.laypage.render({
  25. elem: 'paging',
  26. count: data.number,
  27. limit: 20,
  28. first: '首页',
  29. last: '尾页',
  30. curr: data.p,
  31. groups: 5,
  32. jump: function (obj, first) {
  33. if (!first) {
  34. console.log('第' + obj.curr + '页')
  35. getNews(url, obj.curr)
  36. }
  37. }
  38. });
  39. }
  40. })
  41. }
  42. $('.option').on('click', function (e) {
  43. if (e.target.name === 'enterprisedynamic') {
  44. url = enterprisedynamic;
  45. } else if (e.target.name === 'industrynews') {
  46. url = industrynews;
  47. } else if (e.target.name === 'policies') {
  48. url = policies;
  49. }
  50. getNews(url);
  51. });
  52. getNews(url);
  53. });