Heim  >  Artikel  >  Web-Frontend  >  Einführung in die Erweiterungsfunktionen von Bootstrap

Einführung in die Erweiterungsfunktionen von Bootstrap

零下一度
零下一度Original
2017-06-25 09:14:281199Durchsuche

1. Erweiterte Funktionen

1. Während der Initialisierung wird automatisch ein Auswahltag erstellt

2. Wenn der Auswahlwert geändert wird, ändert sich auch das Datum automatisch wird als Button-Click-Ereignis bezeichnet

3. Klicken Sie hier für eine Vorschau

4. Github-Adresse:

2. Effektanzeige

3. So verwenden Sie

1. Ersetzen Sie die ursprüngliche Datei daterangepicker.js.
2. Die Aufrufmethode ist die gleiche wie zuvor. $('#config-demo').daterangepicker();

4. Code-Implementierung

 1  /* 扩展该组件:增加一个select  */ 2         var _this = this; 3  4         var selectItem = '<select id="dateranepicker_select" class="form-control width150 inline-block">'; 5         selectItem += '<option>今日</option>'; 6         selectItem += '<option>昨日</option>'; 7         selectItem += '<option selected="selected">最近7日</option>'; 8         selectItem += '<option>最近15日</option>'; 9         selectItem += '<option>最近30日</option>';10         selectItem += '<option>本月</option>';11         selectItem += '<option>上月</option>';12         selectItem += '</select>';13 14         this.element.parent().append(selectItem);15 16         $(document).on('change','#dateranepicker_select',function(){17 18             function auto0(num){19                 return num>10?num:'0'+num;20             }21 22             var val = $(this).val();23             var c_start_date = new Date();24             var c_end_date = new Date();25             if(val=='今日'){26 27             }28             else if(val=='昨日'){29                 c_start_date.setDate(c_start_date.getDate()-1);30                 c_end_date.setDate(c_end_date.getDate()-1);31             }32             else if(val=='最近7日'){33                 c_start_date.setDate(c_start_date.getDate()-7);34                 c_end_date.setDate(c_end_date.getDate()-1);35             }36             else if(val=='最近15日'){37                 c_start_date.setDate(c_start_date.getDate()-15);38                 c_end_date.setDate(c_end_date.getDate()-1);39             }40             else if(val=='最近30日'){41                 c_start_date.setDate(c_start_date.getDate()-30);42                 c_end_date.setDate(c_end_date.getDate()-1);43             }44             else if(val=='本月'){45                 var cyear = c_start_date.getFullYear();46                 var cmonth = c_start_date.getMonth();47 48                 c_start_date = new Date(cyear,cmonth,1);49                 c_end_date  =new Date(cyear+'-'+ (cmonth+1) +'-'+new Date(cyear,cmonth+1,0).getDate());50 51             }52             else if(val=='上月'){53                 var cyear = c_start_date.getFullYear();54                 var cmonth = c_start_date.getMonth()-1;55                 c_start_date = new Date(cyear,cmonth,1);56                 c_end_date  =new Date(cyear+'-'+ (cmonth+1) +'-'+new Date(cyear,cmonth+1,0).getDate());57             }58             _this.setStartDate(c_start_date);59             _this.setEndDate(c_end_date);60 61             timespanStr =auto0(c_start_date.getMonth()+1)+'/'+ auto0(c_start_date.getDate()) + '/'+c_start_date.getFullYear()+'-'+ auto0(c_end_date.getMonth()+1) + '/' +auto0(c_end_date.getDate()) + '/' +c_end_date.getFullYear();62 63             _this.element.val(timespanStr);64             _this.hide();65             _this.element.trigger('apply.daterangepicker', _this);66             /* 扩展该组件 end  */67 68 69 70         });

Das obige ist der detaillierte Inhalt vonEinführung in die Erweiterungsfunktionen von Bootstrap. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn