lxw
2020-07-11 9db52f2f2dd3665fe9da1ae5657e0167c3a34d40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function $(id){
    return document.getElementById(id);
}
 
function geib(id){
    return document.getElementById(id);
}
 
function elesByName(name){
    return document.getElementsByName(name);
}
 
function elesByTag(name){
    return document.getElementsByTagName(name);
}
 
function createEle(name){
    return document.createElement(name);
}
 
//封装trim函数
String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g,"");
};
    
    //封装ajax
    //参数:请求方式,请求url,发送的数据,回调函数
      function $ajax(method,url,data,callback){
          var xhr;
          if(window.XMLHttpRequest){
              xhr=new XMLHttpRequest();
          }else{
              xhr=new ActiveXObject('Micsoft.XMLHTTP');
          }
          xhr.open(method, url, true);
          xhr.onreadystatechange=function(){
              if(xhr.readyState==4 && xhr.status==200)
              callback(xhr.responseText);
          };
          if(method.toLowerCase()=="post"){
              xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
          }
          xhr.send(data);
      }
    
      
  
 
      /**
       * @param   d the delimiter
       * @param   p the pattern of your date
       * @author  meizz
       * @author  kimsoft add w+ pattern
       */
      Date.prototype.format = function(style) {
          var o = {
              "M+" : this.getMonth() + 1, //month
              "d+" : this.getDate(),      //day
              "h+" : this.getHours(),     //hour
              "m+" : this.getMinutes(),   //minute
              "s+" : this.getSeconds(),   //second
              "w+" : "\u65e5\u4e00\u4e8c\u4e09\u56db\u4e94\u516d".charAt(this.getDay()),   //week
              "q+" : Math.floor((this.getMonth() + 3) / 3),  //quarter
              "S"  : this.getMilliseconds() //millisecond
          };
          if (/(y+)/.test(style)) {
              style = style.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
          }
          for(var k in o){
              if (new RegExp("("+ k +")").test(style)){
                  style = style.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
              }
          }
          return style;
      };
 
      /**
       * @param d the delimiter
       * @param p the pattern of your date
       * @rebuilder kimsoft
       * @version build 2006.12.15
       */
      String.prototype.toDate = function(delimiter, pattern) {
          delimiter = delimiter || "-";
          pattern = pattern || "ymd";
          var a = this.split(delimiter);
          var y = parseInt(a[pattern.indexOf("y")], 10);
          //remember to change this next century ;)
          if(y.toString().length <= 2) y += 2000;
          if(isNaN(y)) y = new Date().getFullYear();
          var m = parseInt(a[pattern.indexOf("m")], 10) - 1;
          var d = parseInt(a[pattern.indexOf("d")], 10);
          if(isNaN(d)) d = 1;
          return new Date(y, m, d);
      };