commons.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. $(function(){ $(document.body).height($(window).height()); });
  2. var dgRowSize=Math.ceil(($(window).height()-135)/33); // 计算DataGrid一页需要多少行
  3. /**
  4. * 日期格式化
  5. *
  6. * @param format
  7. * @returns
  8. */
  9. Date.prototype.format = function(format) {
  10. var o = {
  11. "M+" : this.getMonth() + 1, // month
  12. "d+" : this.getDate(), // day
  13. "h+" : this.getHours(), // hour
  14. "m+" : this.getMinutes(), // minute
  15. "s+" : this.getSeconds(), // second
  16. "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
  17. "S" : this.getMilliseconds()
  18. }
  19. if (/(y+)/.test(format)) {
  20. format = format.replace(RegExp.$1, (this.getFullYear() + "")
  21. .substr(4 - RegExp.$1.length));
  22. }
  23. for ( var k in o) {
  24. if (new RegExp("(" + k + ")").test(format)) {
  25. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
  26. : ("00" + o[k]).substr(("" + o[k]).length));
  27. }
  28. }
  29. return format;
  30. }
  31. var numberformat=function (val, rec) {
  32. if (val != null && !isNaN(val)) {
  33. return parseFloat(val).toFixed(0);//格式化,保留两位小数
  34. }else{
  35. return val;
  36. }
  37. }