main.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. (function () {
  2. $("[data-toggle='tooltip']").tooltip();
  3. })();
  4. function showError($msg,$id) {
  5. if(!$id){
  6. $id = "#form-error-message"
  7. }
  8. $($id).addClass("error-message").removeClass("success-message").text($msg).show();
  9. return false;
  10. }
  11. function showSuccess($msg,$id) {
  12. if(!$id){
  13. $id = "#form-error-message"
  14. }
  15. $($id).addClass("success-message").removeClass("error-message").text($msg).show();
  16. return true;
  17. }
  18. Date.prototype.format = function(fmt) {
  19. var o = {
  20. "M+" : this.getMonth()+1, //月份
  21. "d+" : this.getDate(), //日
  22. "h+" : this.getHours(), //小时
  23. "m+" : this.getMinutes(), //分
  24. "s+" : this.getSeconds(), //秒
  25. "q+" : Math.floor((this.getMonth()+3)/3), //季度
  26. "S" : this.getMilliseconds() //毫秒
  27. };
  28. if(/(y+)/.test(fmt)) {
  29. fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  30. }
  31. for(var k in o) {
  32. if(new RegExp("("+ k +")").test(fmt)){
  33. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  34. }
  35. }
  36. return fmt;
  37. };
  38. function formatBytes($size) {
  39. var $units = [" B", " KB", " MB", " GB", " TB"];
  40. for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
  41. return $size.toFixed(2) + $units[$i];
  42. }