分享实用的JavaScript代码库
2018-06-24 01:14:10来源:未知 阅读 ()
1 var keyCodeMap = {
2 8: 'Backspace',
3 9: 'Tab',
4 13: 'Enter',
5 16: 'Shift',
6 17: 'Ctrl',
7 18: 'Alt',
8 19: 'Pause',
9 20: 'Caps Lock',
10 27: 'Escape',
11 32: 'Space',
12 33: 'Page Up',
13 34: 'Page Down',
14 35: 'End',
15 36: 'Home',
16 37: 'Left',
17 38: 'Up',
18 39: 'Right',
19 40: 'Down',
20 42: 'Print Screen',
21 45: 'Insert',
22 46: 'Delete',
23 48: '0',
24 49: '1',
25 50: '2',
26 51: '3',
27 52: '4',
28 53: '5',
29 54: '6',
30 55: '7',
31 56: '8',
32 57: '9',
33 65: 'A',
34 66: 'B',
35 67: 'C',
36 68: 'D',
37 69: 'E',
38 70: 'F',
39 71: 'G',
40 72: 'H',
41 73: 'I',
42 74: 'J',
43 75: 'K',
44 76: 'L',
45 77: 'M',
46 78: 'N',
47 79: 'O',
48 80: 'P',
49 81: 'Q',
50 82: 'R',
51 83: 'S',
52 84: 'T',
53 85: 'U',
54 86: 'V',
55 87: 'W',
56 88: 'X',
57 89: 'Y',
58 90: 'Z',
59 91: 'Windows',
60 93: 'Right Click',
61 96: 'Numpad 0',
62 97: 'Numpad 1',
63 98: 'Numpad 2',
64 99: 'Numpad 3',
65 100: 'Numpad 4',
66 101: 'Numpad 5',
67 102: 'Numpad 6',
68 103: 'Numpad 7',
69 104: 'Numpad 8',
70 105: 'Numpad 9',
71 106: 'Numpad *',
72 107: 'Numpad +',
73 109: 'Numpad -',
74 110: 'Numpad .',
75 111: 'Numpad /',
76 112: 'F1',
77 113: 'F2',
78 114: 'F3',
79 115: 'F4',
80 116: 'F5',
81 117: 'F6',
82 118: 'F7',
83 119: 'F8',
84 120: 'F9',
85 121: 'F10',
86 122: 'F11',
87 123: 'F12',
88 144: 'Num Lock',
89 145: 'Scroll Lock',
90 182: 'My Computer',
91 183: 'My Calculator',
92 186: ';',
93 187: '=',
94 188: ',',
95 189: '-',
96 190: '.',
97 191: '/',
98 192: '`',
99 219: '[',
100 220: '\\',
101 221: ']',
102 222: '\''
103 };
104
105 // 数据请求封装
106 $.extend({
107 getJson: function (url, data, success) {//getJson--同步方法---获取会员信息,推荐人
108 return $.ajax({
109 url: url,
110 type: 'get',
111 dataType: 'json',
112 async: false,
113 cache: true,
114 data: data,
115 success: function (result) {
116 success(result);
117 }
118 });
119 },
120 getAsyncJson: function (url, data, success) {
121 return $.ajax({
122 url: url,
123 type: 'get',
124 dataType: 'json',
125 async: true,
126 cache: true,
127 data: data,
128 success: function (result) {
129 success(result);
130 }
131 });
132 },
133 postAsyncJson: function (url, data, success) {
134 return $.ajax({
135 url: url,
136 type: 'post',
137 dataType: 'json',
138 //contentType: "application/json",
139 beforeSend: function (xhr) {
140 xhr.setRequestHeader("XSRF-TOKEN",
141 $('input:hidden[name="__RequestVerificationToken"]').val());
142 },
143 async: true,
144 cache: false,
145 data: data,
146 success: function (result) {
147 success(result);
148 }
149 });
150 },
151 postAsyncContentJson: function (url, data, success) {
152 data = JSON.stringify(data);
153 return $.ajax({
154 url: url,
155 type: 'post',
156 dataType: 'json',
157 contentType: "application/json",
158 beforeSend: function (xhr) {
159 xhr.setRequestHeader("XSRF-TOKEN",
160 $('input:hidden[name="__RequestVerificationToken"]').val());
161 },
162 async: true,
163 cache: false,
164 data: data,
165 success: function (result) {
166 success(result);
167 }
168 });
169 },
170 postJson: function (url, data, success) {
171 return $.ajax({
172 url: url,
173 type: 'post',
174 dataType: 'json',
175 beforeSend: function (xhr) {
176 xhr.setRequestHeader("XSRF-TOKEN",
177 $('input:hidden[name="__RequestVerificationToken"]').val());
178 },
179 async: false,
180 cache: false,
181 data: data,
182 success: function (result) {
183 success(result);
184 }
185 });
186 },
187 getHtml: function (url, data, success) {
188 return $.ajax({
189 url: url,
190 type: 'get',
191 dataType: 'html',
192 async: false,
193 cache: false,
194 data: data,
195 success: function (result) {
196 success(result);
197 }
198 });
199 },
200 getAsyncHtml: function (url, data, success) {
201 return $.ajax({
202 url: url,
203 type: 'get',
204 dataType: 'html',
205 async: true,
206 cache: false,
207 data: data,
208 success: function (result) {
209 success(result);
210 }
211 });
212 },
213 postHtml: function (url, data, success) {
214 return $.ajax({
215 url: url,
216 type: 'post',
217 dataType: 'html',
218 async: true,
219 cache: false,
220 data: data,
221 success: function (result) {
222 success(eval(result));
223 }
224 });
225 },
226 commonUploadImg: function (fileToUploadId, uploadFileType, isCompress, success) {
227 if (!fileToUploadId) {
228 layer.msg('上传控件ID不能为空!');
229 return;
230 }
231 var formData = new FormData();
232 var files = $('#' + fileToUploadId)[0].files[0];
233 if (!files) {
234 layer.msg('请选择图片文件');
235 return;
236 }
237 if (files.size > 5242880) {
238 layer.msg('请上传小于5M以下的图片');
239 return;
240 }
241 if (files.type == 'image/jpeg' || files.type == 'image/png') {
242
243 } else {
244 layer.msg('请上传图片文件!');
245 return;
246 }
247 formData.append("file", files);
248 formData.append("userId", user_id);
249 formData.append("uploadFileType", uploadFileType);
250 formData.append("isCompress", isCompress);
251 $.ajax({
252 url: '',
253 type: "POST",
254 data: formData,
255 processData: false