jQuery.Extend.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. 
  2. //****************************************************************************************//
  3. //**************************************jquery扩展****************************************//
  4. $.fn.extend({
  5. getFormData: function () {
  6. /// <summary>
  7. /// 获取form表单内容,返回json数据
  8. /// </summary>
  9. var dataArray = $(this).serializeArray();
  10. var jsonData = {};
  11. $.each(dataArray, function () {
  12. if (jsonData[this["name"]]) {
  13. jsonData[this["name"]] = jsonData[this["name"]] + "," + $.trim(this["value"]);
  14. } else {
  15. jsonData[this["name"]] = $.trim(this["value"]);
  16. }
  17. });
  18. return jsonData;
  19. }
  20. });
  21. $.extend({
  22. dateFormatter: function (date) {
  23. return date.format("yyyy-MM-dd");
  24. },
  25. dateFieldFamtter: function (value, row, index) {
  26. if (!value) return "";
  27. value = value || '';
  28. return value.toDateString('yyyy-MM-dd hh:mm:ss.S');
  29. },
  30. createGUID: function () {//生成GUID
  31. var s4 = function () {
  32. return Math.floor((1 + Math.random()) * 0x10000)
  33. .toString(16)
  34. .substring(1);
  35. }
  36. var guid = s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
  37. return guid;
  38. },
  39. createViewPage: function (uniqueID) {
  40. var _this = $("#" + uniqueID);
  41. _this["get"] = function (jqExp) {
  42. return _this.find(jqExp);
  43. };
  44. return _this;
  45. },
  46. isNullOrEmpty: function (value) {
  47. /// <summary>
  48. /// 验证对象是否为undefined||null||empty
  49. /// return true||false||undefined
  50. /// </summary>
  51. if (typeof (value).toLowerCase() != "string") {
  52. return undefined;
  53. }
  54. return (!value || !value.length);
  55. },
  56. decode: function (string) {
  57. string = string.replace(/\&quot;/g, "\"");
  58. string = string.replace(/\@~/g, "\[");
  59. string = string.replace(/\@!/g, "\]");
  60. string = string.replace(/\\\\/g, "\\");
  61. string = string.replace(/\&lt;/g, "<");
  62. string = string.replace(/\&gt;/g, ">");
  63. return string;
  64. },
  65. getUrlParameter: function (asName){
  66. var lsURL=window.location.href;
  67. loU = lsURL.split("?");
  68. if (loU.length>1){
  69. var loallPm = loU[1].split("&");
  70. for (var i=0; i<loallPm.length; i++){
  71. var loPm = loallPm[i].split("=");
  72. if (loPm[0].toLowerCase()==asName.toLowerCase()){
  73. if (loPm.length>1){
  74. return loPm[1];
  75. }else{
  76. return "";
  77. }
  78. }
  79. }
  80. }
  81. return null;
  82. }
  83. });
  84. //******************************************End******************************************//
  85. //***************************************************************************************//