jquery.gcjs.js
23.2 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
jQuery.extend({
isEmail: function(str) {
return /^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/.test($.trim(str));
},
isIDCard: function(obj) {
var aCity = {11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙 江", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖 北", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西 藏", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国 外"};
var iSum = 0;
//var info = "";
var strIDno = obj;
var idCardLength = strIDno.length;
if (!/^\d{17}(\d|x)$/i.test(strIDno) && !/^\d{15}$/i.test(strIDno))
return false; //非法身份证号
if (aCity[parseInt(strIDno.substr(0, 2))] == null)
return false;// 非法地区
// 15位身份证转换为18位
if (idCardLength == 15)
{
sBirthday = "19" + strIDno.substr(6, 2) + "-" + Number(strIDno.substr(8, 2)) + "-" + Number(strIDno.substr(10, 2));
var d = new Date(sBirthday.replace(/-/g, "/"))
var dd = d.getFullYear().toString() + "-" + (d.getMonth() + 1) + "-" + d.getDate();
if (sBirthday != dd)
return false; //非法生日
strIDno = strIDno.substring(0, 6) + "19" + strIDno.substring(6, 15);
strIDno = strIDno + GetVerifyBit(strIDno);
}
// 判断是否大于2078年,小于1900年
var year = strIDno.substring(6, 10);
if (year < 1900 || year > 2078)
return false;//非法生日
//18位身份证处理
//在后面的运算中x相当于数字10,所以转换成a
strIDno = strIDno.replace(/x$/i, "a");
sBirthday = strIDno.substr(6, 4) + "-" + Number(strIDno.substr(10, 2)) + "-" + Number(strIDno.substr(12, 2));
var d = new Date(sBirthday.replace(/-/g, "/"))
if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate()))
return false; //非法生日
// 身份证编码规范验证
for (var i = 17; i >= 0; i --)
iSum += (Math.pow(2, i) % 11) * parseInt(strIDno.charAt(17 - i), 11);
if (iSum % 11 != 1)
return false;// 非法身份证号
// 判断是否屏蔽身份证
var words = new Array();
words = new Array("11111119111111111", "12121219121212121");
for (var k = 0; k < words.length; k++) {
if (strIDno.indexOf(words[k]) != -1) {
return false;
}
}
return true;
},
isUrl: function(str) {
return /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/.test($.trim(str));
},
isInt: function(str) {
return /^[-\+]?\d+$/.test($.trim(str));
},
isUserID: function(str) {
return /^\s*[A-Za-z0-9_-]{6,20}\s*$/.test($.trim(str));
},
isMobile: function(str) {
return $.trim(str) !== '' && /^1[3|4|5|8][0-9]\d{4,8}$/.test($.trim(str));
},
isChinese: function(str) {
return $.trim(str) != '' & !/[^\u4e00-\u9fa5]/.test($.trim(str));
},
isEnglish:function(str){
return $.trim(str) != '' & !/[^a-zA-Z]/.test($.trim(str));
},
isPassword: function(str) {
return /^[^\u4e00-\u9fa5\s]{6,20}$/.test($.trim(str));
},
isFloat: function(str) {
return /^(\+|-)?\d+($|\.\d+$)/.test($.trim(str));
},
isNumber: function(str) {
return !$.isEmpty(str) && !isNaN(str);
},
isIP: function(str) {
if (/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.test($.trim(str))) {
if (RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 < 256)
return true;
}
return false;
},
isDate: function(str) {
var r = $.trim(str).split("-");
if (r == null)
return false;
var d = new Date(r[0], r[1] - 1, r[2]);
return (d.getFullYear() == r[0] && (d.getMonth() + 1) == r[1] && d.getDate() == r[2]);
},
htmlEncode: function(str) {
str = str.replace(/&/g, '&');
str = str.replace(/</g, '<');
str = str.replace(/>/g, '>');
str = str.replace(/(?:\t| |\v|\r)*\n/g, '<br />');
str = str.replace(/ /g, ' ');
str = str.replace(/\t/g, ' ');
str = str.replace(/\x22/g, '"');
str = str.replace(/\x27/g, ''');
return $.trim(str);
},
htmlDecode: function(str) {
str = str.replace(/&/gi, '&');
str = str.replace(/ /gi, ' ');
str = str.replace(/"/gi, '"');
str = str.replace(/'/g, "'");
str = str.replace(/</gi, '<');
str = str.replace(/>/gi, '>');
str = str.replace(/<br[^>]*>(?:(\r\n)|\r|\n)?/gi, '\n');
return $.trim(str);
},
preview: function(str) {
var testwin = open("");
testwin.document.open();
testwin.document.write(str);
testwin.document.close();
},
isEmpty: function(str) {
return $.trim(str) == '' || str == undefined
},
arrayIndexOf: function(arr, substr, start) {
var ta, rt, d = '\0';
if (start != null) {
ta = arr.slice(start);
rt = start;
} else {
ta = arr;
rt = 0;
}
var str = d + ta.join(d) + d, t = str.indexOf(d + substr + d);
if (t == -1)
return -1;
rt += str.slice(0, t).replace(/[^\0]/g, '').length;
return rt;
},
arrayLastIndexOf: function(arr, substr, start) {
var ta, rt, d = '\0';
if (start != null) {
ta = arr.slice(start);
rt = start;
} else {
ta = arr;
rt = 0;
}
ta = ta.reverse();
var str = d + ta.join(d) + d, t = str.indexOf(d + substr + d);
if (t == -1)
return -1;
rt += str.slice(t).replace(/[^\0]/g, '').length - 2;
return rt;
},
arrayReplace: function(arr, reg, rpby) {
var ta = arr.slice(0), d = '\0';
var str = ta.join(d);
str = str.replace(reg, rpby);
return str.split(d);
},
arraySearch: function(arr, reg) {
var ta = arr.slice(0), d = '\0', str = d + ta.join(d) + d, regstr = reg.toString();
reg = new RegExp(regstr.replace(/\/((.|\n)+)\/.*/g, '\\0$1\\0'), regstr.slice(regstr.lastIndexOf('/') + 1));
t = str.search(reg);
if (t == -1)
return -1;
return str.slice(0, t).replace(/[^\0]/g, '').length;
},
nullundefined: function(str) {
},
setClipboard: function(maintext) {
if (window.clipboardData) {
window.clipboardData.setData("Text", maintext);
alert("复制成功!");
}
else if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("被浏览器拒绝!\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signed.applets.codebase_principal_support'设置为'true'");
return;
}
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if (!clip)
return;
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans)
return;
trans.addDataFlavor('text/unicode');
var str = new Object();
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
var copytext = txt;
str.data = copytext;
trans.setTransferData("text/unicode", str, copytext.length * 2);
var clipid = Components.interfaces.nsIClipboard;
if (!clip)
return false;
clip.setData(trans, null, clipid.kGlobalClipboard);
alert("复制成功!")
}
}
});
(function($) {
$.fn.isInt = function() {
return $.isInt($(this).val());
}
})(jQuery);
(function($) {
$.fn.isIDCard = function() {
return $.isIDCard($(this).val());
}
})(jQuery);
(function($) {
$.fn.isEnglish = function() {
return $.isEnglish($(this).val());
}
})(jQuery);
(function($) {
$.fn.isEmail = function() {
return $.isEmail($(this).val());
}
})(jQuery);
(function($) {
$.fn.isDate = function() {
return $.isDate($(this).val());
}
})(jQuery);
(function($) {
$.fn.isIP = function() {
return $.isIP($(this).val());
}
})(jQuery);
(function($) {
$.fn.isChinese = function() {
return $.isChinese($(this).val());
}
})(jQuery);
(function($) {
$.fn.isEmpty = function() {
return $.isEmpty($(this).val());
}
})(jQuery);
(function($) {
$.fn.isUrl = function() {
return $.isUrl($(this).val());
}
})(jQuery);
(function($) {
$.fn.isFloat = function() {
return $.isFloat($(this).val());
}
})(jQuery);
(function($) {
$.fn.isNumber = function() {
return $.isNumber($(this).val());
}
})(jQuery);
(function($) {
$.fn.isUserID = function() {
return $.isUserID($(this).val());
}
})(jQuery);
(function($) {
$.fn.isPassword = function() {
return $.isPassword($(this).val());
}
})(jQuery);
(function($) {
$.fn.isMobile = function() {
return $.isMobile($(this).val());
}
})(jQuery);
(function($) {
$.fn.len = function() {
return $(this).val().length;
}
})(jQuery);
(function($) {
$.fn.checked = function() {
return $(this).get(0).checked();
}
})(jQuery);
(function($){
$.fn.resizeImage = function(iwidth,iheight){
var w = $(this).width() ;
var h = $(this).height() ;
var _img = new Image();
_img.src = $(this).attr("src");
if(_img.width > _img.height)
{
h = (_img.height / _img.width) *w;
w = (_img.width > iwidth) ? iwidth : _img.width;
}
else if(_img.width < _img.height)
{
w= (_img.width / _img.height) * h ;
h= (_img.height > iheight) ? iheight : _img.height;
}
else
{
h = (_img.height > iheight) ? iheight : _img.height;
w= (_img.width > iwidth) ? iwidth : _img.width;
}
$(this).css({width: w+ "px",height:h+"px"});
}
})(jQuery);
(function($) {
$.fn.breakWords = function(width) {
var _this = $(this);
var content = _this.html();
if (content == undefined) {
return;
}
if (content.length <= width) {
_this.html(content);
}
else {
var str = '';
for (var i = 0; i < content.length; i++) {
if (i % width != 0) {
str += content.substr(i, 1);
}
else {
if (i != 0) {
str += "<br/>" + content.substr(i, 1);
}
}
}
_this.html(str);
}
}
})(jQuery);
(function($) {
$.fn.limitWidth = function() {
var _this = $(this);
var elments = _this.getElementsByTagName("*");
for (var i = 0; i < elments.length; i++) {
if (parseInt(elments[i].getAttribute("width")) > width) {
elments[i].setAttribute("width", width - 1);
}
if (elments[i].style.width) {
if (parseInt(elments[i].style.width) > width) {
elments[i].style.width = width - 1;
}
}
}
return _this;
}
})(jQuery);
(function($) {
$.fn.limitLength = function(num, inputID,isInput) {
var textarea = $(this);
var input = null;
if (inputID) {
input = $("#" + inputID);
}
if (input) {
isInput?input.val(num - textarea.len()):input.html(num - textarea.len());
}
function limit(textarea, num) {
if (textarea.len() >= num) {
textarea.val(textarea.val().substring(0, num));
}
else {
if (input) {
isInput?input.val(num - textarea.len()):input.html(num - textarea.len());
}
}
}
textarea.keypress(function(e) {
limit($(this), num);
}).keyup(function(e) {
limit($(this), num);
}).mouseup(function(e) {
limit($(this), num);
});
return textarea;
}
})(jQuery);
(function($) {
$.fn.nulldefined = function() {
}
})(jQuery);
var GC = {
addFavorite: function(url, text) //收藏夹
{
if (document.all) {
window.external.addFavorite(url, text);
}
else if (window.sidebar) {
window.sidebar.addPanel(text, url, "");
}
},
holder: function(objid){
var _this = $("#" + objid);
var placeholder = _this.attr("holder");
if($.trim(_this.val())==""){
_this.addClass("placeholder");
_this.val(placeholder);
}
_this.focus(function(){
if($.trim(_this.val())==placeholder){
_this.removeClass("placeholder");
_this.val("");
}
}).blur(function(){
if($.trim(_this.val())==""){
_this.addClass("placeholder");
_this.val(placeholder);
}
});
},
setHomePage: function(obj, vrl) //首页
{
if (confirm('确认要将' + vrl + '设置为首页?')) {
try {
obj.style.behavior = 'url(#default#homepage)';
obj.setHomePage(vrl);
}
catch (e) {
if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e) {
alert("此操作被浏览器拒绝!\n请在浏览器地址栏填写“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage', vrl);
}
}
}
},
undefined: function(variable) {
return typeof variable == 'undefined' ? true : false;
},
form: function(formid) {
if (formid == null || formid == undefined)
{
return document.forms[0];
}
else {
return document.forms[formid];
}
},
openWindow : function(url){
var a = document.createElement("a");
a.setAttribute("href", url);
a.setAttribute("target", "_blank");
a.setAttribute("id", "openwin");
document.body.appendChild(a);
a.click();
},
getElementsByName: function(name) {
var ret = [];
var elements = document.getElementsByTagName("input");
for (var i = 0; i < elements.length; i++) {
if (elements[i].name == name) {
ret.push(elements[i]);
}
}
return ret;
},
checkAll: function(ischecked, formid) {
if (formid) {
$("#" + formid + " input[type='checkbox']").attr("checked", ischecked);
} else {
$("input[type='checkbox']").attr("checked", ischecked);
}
},
selectedCount: function(formid) {
var chks = null;
var n = 0;
if (formid) {
chks = $("#" + formid + " input[type='checkbox']");
} else {
chks = $("input[type='checkbox']");
}
chks.each(function() {
if ($(this).get(0).checked) {
n++;
}
});
return n;
},
selecteds: function(formid) {
var ids = "";
var chks = null;
if (formid) {
chks = $("#" + formid + " input[type='checkbox']");
} else {
chks = $("input[type='checkbox']");
}
chks.each(function() {
if ($(this).get(0).checked) {
if (ids != "") {
ids += ",";
}
ids += $(this).val();
}
});
return ids;
},
allids: function(formid) {
var ids = "";
var chks = null;
if (formid) {
chks = $("#" + formid + " input[type='checkbox']");
} else {
chks = $("input[type='checkbox']");
}
chks.each(function() {
if (ids != "") {
ids += ",";
}
ids += $(this).val();
});
return ids;
},
uncheckAll: function(formid) {
if (formid) {
$("#" + formid + " input[type='checkbox']").attr("checked", false);
} else {
$("input[type='checkbox']").attr("checked", false);
}
}
}
;
(function($) {
$.fn.extend({
"placeholder": function(options) {
options = $.extend({
placeholderColor: '#aaa',
isUseSpan: true, //是否使用插入span标签模拟placeholder的方式,默认false,默认使用value模拟
onInput: true //使用标签模拟(isUseSpan为true)时,是否绑定onInput事件取代focus/blur事件
}, options);
$(this).each(function() {
var _this = this;
var supportPlaceholder = 'placeholder' in document.createElement('input');
if (!supportPlaceholder) {
var defaultValue = $(_this).attr('placeholder');
if (!defaultValue) {
return;
}
var defaultColor = $(_this).css('color');
if (!options.isUseSpan) {
$(_this).focus(function() {
var pattern = new RegExp("^" + defaultValue + "$|^$");
pattern.test($(_this).val()) && $(_this).val('').css('color', defaultColor);
}).blur(function() {
if ($(_this).val() == defaultValue) {
$(_this).css('color', defaultColor);
} else if ($(_this).val().length == 0) {
$(_this).val(defaultValue).css('color', options.placeholderColor)
}
}).trigger('blur');
} else {
var $imitate = $('<span class="wrap-placeholder" style="position:absolute; display:inline-block; overflow:hidden; color:' + options.placeholderColor + '; width:' + $(_this).outerWidth() + 'px; height:' + $(_this).outerHeight() + 'px;">' + defaultValue + '</span>');
$imitate.css({
'margin-left': $(_this).css('margin-left'),
'margin-top': $(_this).css('margin-top'),
'font-size': $(_this).css('font-size'),
'font-family': $(_this).css('font-family'),
'font-weight': $(_this).css('font-weight'),
'padding-left': parseInt($(_this).css('padding-left')) + 2 + 'px',
'line-height': _this.nodeName.toLowerCase() == 'textarea' ? $(_this).css('line-weight') : $(_this).outerHeight() + 'px',
'padding-top': _this.nodeName.toLowerCase() == 'textarea' ? parseInt($(_this).css('padding-top')) + 2 : 0,
"left":$(_this).position().left + "px",
"top":$(_this).position().top + "px"
});
$(_this).before($imitate.click(function() {
$(_this).trigger('focus');
}));
$(_this).val().length != 0 && $imitate.hide();
if (!options.onInput) {
//绑定oninput/onpropertychange事件
var inputChangeEvent = typeof(_this.oninput) == 'object' ? 'input' : 'propertychange';
$(_this).bind(inputChangeEvent, function() {
$imitate[0].style.display = $(_this).val().length != 0 ? 'none' : 'inline-block';
});
} else {
$(_this).focus(function() {
$imitate.hide();
}).blur(function() {
/^$/.test($(_this).val()) && $imitate.show();
});
}
}
}
});
return this;
}
});
})(jQuery);
(function($) {
$.fn.extend({
"initSelect": function(options) {
options = $.extend({
debug: false,
maxlength:10
}, options);
$(this).each(function() {
var _input =$(this);
var _div = $("#" + $(this).attr("id") + "_div");
var _ul = $("#" + $(this).attr("id") + "_ul");
_div.mouseenter(function(){
_ul.show();
}).mouseleave(function(){
_ul.hide();
});
var txt = "";
var val = _input.val();
$("li",_ul).each(function(){
var item = $(this);
if(item.attr("val")==val){
$("span",$(".selected",_div)).html( item.attr("text").substr(0,options.maxlength));
}
if( item.attr("haschild")=="true"){
var _cul = $("#" + _input.attr("id") + "_" + item.attr("val")+"_ul");
item.mouseenter(function(){
_cul.show();
}).mouseleave(function(){
_cul.hide();
});
}
}).click(function(ev){
var txt1 = $(this).attr("text");
var val1 = $(this).attr("val");
$("ul",_div).hide();
_input.val( val1 );
$("span",$(".selected",_div)).html(txt1.substr(0,options.maxlength));
ev.stopPropagation();
});;
});
return this;
}
});
})(jQuery);