util.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. function syntaxHighlight(json) {
  2. if (typeof json != 'string') {
  3. json = JSON.stringify(json, undefined, 2);
  4. }
  5. json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
  6. return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function(match) {
  7. var cls = 'number';
  8. if (/^"/.test(match)) {
  9. if (/:$/.test(match)) {
  10. cls = 'key';
  11. } else {
  12. cls = 'string';
  13. }
  14. } else if (/true|false/.test(match)) {
  15. cls = 'boolean';
  16. } else if (/null/.test(match)) {
  17. cls = 'null';
  18. }
  19. return '<span class="' + cls + '">' + match + '</span>';
  20. });
  21. };
  22. // var t = null;
  23. // t = setTimeout(time, 1000); //開始运行
  24. function time() {
  25. // clearTimeout(t); //清除定时器
  26. dt = new Date();
  27. var y = dt.getFullYear();
  28. var mt = dt.getMonth() + 1;
  29. var day = dt.getDate();
  30. var h = dt.getHours(); //获取时
  31. var m = dt.getMinutes(); //获取分
  32. var s = dt.getSeconds(); //获取秒
  33. return Appendzero(y) + "-" + Appendzero(mt) + "-" + Appendzero(day) + " " + Appendzero(h) + ":" + Appendzero(m) + ":" + Appendzero(s);
  34. // t = setTimeout(time, 1000); //设定定时器,循环运行
  35. }
  36. //个位数补零
  37. function Appendzero(obj) {
  38. if (obj < 10) return "0" + obj;
  39. else return obj;
  40. }
  41. //滚动到底部
  42. function scrollBottom() {
  43. $('.data-view').animate({ scrollTop: $('.data-view').prop('scrollHeight') }, 1000);
  44. }