tag.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. $(function() {
  2. $('#loading').modal('show');
  3. fetchJSON("/api/tag/hot?page=0&size=50", {}, "get", function(ret) {
  4. if (ret.code === 0) {
  5. if (ret.data.length > 0) {
  6. $("#hotTag").empty();
  7. for (var i = 0; i < ret.data.length; i++) {
  8. $("#hotTag").append(
  9. $("<a>", {
  10. href: "list_index.html?q=" + ret.data[i].keyword,
  11. text: ret.data[i].keyword,
  12. class: "tagItem"
  13. })
  14. );
  15. }
  16. }
  17. } else {
  18. console.log(ret.msg);
  19. }
  20. $('#loading').modal('hide');
  21. });
  22. $("#search").on("click", function(e) {
  23. e.preventDefault();
  24. submitSearch($("#keyword"));
  25. });
  26. $("#keyword").on("keyup", function(e) {
  27. e.preventDefault();
  28. if (e.keyCode === 13) submitSearch($("#keyword"));
  29. });
  30. function submitSearch(control) {
  31. if (control.val().trim() === "") {
  32. control.focus();
  33. return;
  34. }
  35. var keylist = encodeURIComponent(control.val().trim());
  36. window.location.href = "list_index.html?q=" + keylist;
  37. }
  38. });