forked from huanhuan1989/javascript-jQuery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path常用jQuery code
423 lines (396 loc) · 10.7 KB
/
常用jQuery code
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
/**
* hhBase 平台js
* User: huanhuan
* QQ: 651471385
* Email: [email protected]
* 微博: huanhuan的天使
* Date: 13-9-1
* Time: 上午10:05
* Dependence jquery-1.7.2.min.js
*/
var fn = {};
//鼠标划过显示隐藏方法
fn._hoverShow = function(infor){
var option = {
id:'',
addClass:'',
showBox:'',
showTriangle:'',
mouseenter:function(){},
mouseleave:function(){}
}
//这个地方如果不用for循环来弄的,那么可以用extend来合并使用!
/*
for(var i in infor){
if(option.hasOwnProperty(i)){
option[i] = infor[i];
}
}
*/
option = $.extend(option, infor);
$(option.id).on({
'mouseenter' : function(e){
$(this).addClass(option.addClass);
$(this).find('.'+option.showBox).show();
$(this).find('.'+option.showTriangle).show();
option.mouseenter();
},
'mouseleave' : function(e){
$(this).removeClass(option.addClass);
$(this).find('.'+option.showBox).hide();
$(this).find('.'+option.showTriangle).hide();
option.mouseleave();
}
});
}
fn.hoverShow = function(){
fn._hoverShow({
id:$('[data-rule="hoverShow"]'),
addClass:'topmenu-dropdown-hover'
});
fn._hoverShow({
id:$('[data-rule="hoverShow-weixin"]'),
showBox:'topmenu-item-weix',
showTriangle:'weix-triangle'
});
}
//checkbox 全选
fn._checkBox = function(num){
var option = {
id:'',
itemClass:'',
listClass:'',
clickCheckRun:function(){}
}
option = $.extend(option,num);
$(option.id).bind({
click:function(){
$('.'+option.itemClass+',.'+option.listClass).attr('checked',($(this).attr('checked') == "checked"));
option.clickCheckRun();
}
});
$('.'+option.listClass).bind({
click:function(){
$(this).parents('.toolbar_box').find('.'+option.itemClass)
.attr('checked',($(this).attr('checked') == "checked"));
option.clickCheckRun();
}
});
}
fn.checkBox = function(){
fn._checkBox({
id:$('[data-rule="checkAll"]'),
itemClass:'chkItem',
listClass:'checkListAll'
});
}
//判断文本框的值是否为空,有值的情况就隐藏提示语,没有值就显示
fn._keyup = function(keys){
var option = {
id:'',
keyup:function(){},
blur:function(){}
}
for(var i in keys){
if(option.hasOwnProperty(i)){
option[i] = keys[i];
}
}
$(option.id).each(function(){
var thisVal=$(option.id).val();
//判断文本框的值是否为空,有值的情况就隐藏提示语,没有值就显示
if(thisVal!=""){
$(this).siblings("span").hide();
}else{
$(this).siblings("span").show();
}
$(this).live({
keyup:function(){
var val=$(this).val();
$(this).siblings("span").hide();
},
blur:function(){
var val=$(this).val();
if(val!=""){
$(this).siblings("span").hide();
}else{
$(this).siblings("span").show();
}
}
});
$(this).siblings("span").click(function(){
$(option.id).focus();
});
});
}
fn.keyup = function(){
fn._keyup({id:$('[data-rule="keyTxt"]')});
fn._keyup({id:$('[data-rule="keyPassword"]')});
}
//TAB 标签切换
fn._showTab = function(op){
var option ={
id : '',
addClass : '',
showClass : '',
clickrun:function(){}
}
for(var i in op){
if(option.hasOwnProperty(i)){
option[i] = op[i];
}
}
$(option.id).find('li').live({
click:function(){
var index = $(this).index();
$(this).addClass('current').siblings().removeClass('current');
$('.'+option.showClass).eq(index).show().siblings('.'+option.showClass).hide();
option.clickrun();
}
});
}
fn.showTab = function(){
fn._showTab({
id:$('[data-rule="dateTab"]'),
addClass:'current',
showClass:'thSupList'
});
}
//文本框 focus blur 方法
fn._placeHolder = function(cfg){
var option = {
id:'',
text:'',
focuscolor:'#000',
blurcolor:'#999',
focusrun:function(){},
blurrun:function(){}
};
for (var i in cfg) {
if (option.hasOwnProperty(i)) {
option[i] = cfg[i];
}
}
$(option.id).live({
focus:function(){
$(this).attr('tempvalue',$(this).val().match(/^\s*(\S+(\s+\S+)*)\s*$/)==
null?'':$(this).val().match(/^\s*(\S+(\s+\S+)*)\s*$/)[1]);
if($(this).attr('tempvalue')==option.text){
$(this).val('');
$(this).css('color',option.focuscolor);
}else{
$(this).css('color',option.focuscolor);
}
option.focusrun();
},
blur:function(){
$(this).attr('tempvalue',$(this).val().match(/^\s*(\S+(\s+\S+)*)\s*$/)==
null?'':$(this).val().match(/^\s*(\S+(\s+\S+)*)\s*$/)[1]);
if($(this).attr('tempvalue').length<1){
$(this).val(option.text);
$(this).css('color',option.blurcolor);
}
option.blurrun();
}
});
}
fn.placeHolder = function(){
fn._placeHolder({id:$('[data-rule="searchQuery"]'),text:'想去哪?'});
fn._placeHolder({id:$('[data-rule="searchMap"]'),text:'想去哪里?'});
}
//文本框 focus blur 方法
fn._txtFocus = function(kval){
var option = {
id:'',
hideInput:'',
inputTxt:'',
focus:function(){},
blur:function(){}
}
for(var i in kval){
if (option.hasOwnProperty(i)){
option[i] = kval[i];
}
}
$(option.id).on({
'focus':function(){
var mail = $(this).val();
if(mail == option.inputTxt){
$(this).val('');
$(this).css('color','#333');
}
option.focus();
},
'blur':function(){
var mail = $(this).val();
if(mail == ''){
$(this).val(option.inputTxt);
$(this).css('color','#999');
}
option.blur();
}
});
}
fn.txtFocus = function(){
fn._textFocus({id:$('[data-rule="nameTxt"]'),inputTxt:'输入用户名'});
}
//密码框文字的显示、隐藏
fn._keyFocus = function(kval){
var option = {
id:'',
hideTd:'',
hideInput:'',
inputTxt:'',
focus:function(){},
blur:function(){}
}
for(var i in kval){
if (option.hasOwnProperty(i)){
option[i] = kval[i];
}
}
$(option.id).on({
'focus':function(){
var text_value = $(this).val();
if (text_value == this.defaultValue) {
$('#'+option.hideInput).hide();
$('#thpassword').show().focus();
}
option.focus();
}
});
$(option.hideTd).on({
'blur':function(){
var text_value = $(this).val();
if (text_value == '') {
$('#'+option.hideInput).show();
$(this).hide();
}
option.blur();
}
});
}
fn.keyFocus = function(){
fn._keyFocus({
id:$('[data-rule="passwordTxt"]'),
hideTd:$('[data-rule="passwordShow"]'),
hideInput:$('#showPwd'),
inputTxt:'输入密码'
});
}
//点击显示 其它地方隐藏
fn.pricePrice = function(){
var pricePrice;
$('[data-rule="pricePrice"]').live({
click:function(event){
var T = $(this);
event.stopPropagation();
T.addClass('thFPriceHover');
$(document).bind('click',function(event){
if(!$(event.target).hasClass('thFPbox')){
T.removeClass('thFPriceHover');
}
});
}
});
}
//点击显示隐藏 简单树结构
fn._filter = function(cfg){
var option = {
id:'',
parentClass:'',
clickClass:'',
showClass:'',
clickrun:function(){}
};
for (var i in cfg) {
if (option.hasOwnProperty(i)) {
option[i] = cfg[i];
}
}
$(option.id).find('.'+option.clickClass).live({
click:function(event){
if ($(this).parents('.'+option.parentClass).find('.'+option.showClass).is(':visible')){
event.stopPropagation();
if($(this).hasClass('thDevelop')){
$(this).addClass('thPackUp');
}
$(this).parents('.'+option.parentClass).find('.'+option.showClass).hide();
}else{
if($(this).hasClass('thDevelop')){
$(this).removeClass('thPackUp');
}
$(this).parents('.'+option.parentClass).find('.'+option.showClass).show();
}
option.clickrun();
}
});
}
fn.filter = function(){
fn._filter({
id:$('[data-rule="dateFilter"]'),
parentClass:'thFilterBox',
clickClass:'thDevelop',
showClass:'thDataFilter'
});
fn._filter({
id:$('[data-rule="serviceFilter"]'),
parentClass:'thFilterBox',
clickClass:'thDevelop',
showClass:'thFilterList'
});
}
//日历 调用方法
fn.setDatePickerLanguage = function(){
jQuery(function($){
$.datepicker.regional['zh'] = {
closeText: '关闭',
prevText: '<上月',
nextText: '下月>',
currentText: '今天',
monthNames: ['一月','二月','三月','四月','五月','六月',
'七月','八月','九月','十月','十一月','十二月'],
monthNamesShort: ['一月','二月','三月','四月','五月','六月',
'七月','八月','九月','十月','十一月','十二月'],
dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'],
dayNamesMin: ['日','一','二','三','四','五','六'],
weekHeader: '周',
dateFormat: 'yy-mm-dd',
firstDay: 1,
isRTL: false,
showMonthAfterYear: true,
yearSuffix: '年'};
$.datepicker.setDefaults($.datepicker.regional['zh']);
});
}
fn.datePickerBind = function(){
$('[data-rule="dataStart"]').datepicker({
defaultDate: "+1w",
onClose: function( selectedDate ) {
$('[data-rule="dataEnd"]').datepicker( "option", "minDate", selectedDate );
}
});
$('[data-rule="dataEnd"]').datepicker({
defaultDate: "+1w",
onClose: function( selectedDate ) {
$('[data-rule="dataStart"]').datepicker( "option", "maxDate", selectedDate );
}
});
}
$(function(){
//平台首页设置样式
$('.platFSList dl:even').css('padding-right','40px');
$('.plFIOMain dl:even').css({'padding-right':'18px','border-right':'1px solid #e0e0e0'});
$('.plFIOMain dl:odd').css({'padding-left':'18px'});
$('.platFRagent dl:even').css('padding-right','32px');
$('.platFRaList li').eq(2).nextAll().find('label').addClass('platFRaLnumber00');
//设置最后一个header-nav的css样式
$('.topHeader-nav li:last').css('padding-right','0');
//fn调用方法
for(fname in fn){
if(fname.indexOf('_') == -1){
fn[fname]();
}
}
});