Introduction to the extension functions of bootstrap
1. Extended functions
1. During initialization, a select tag will be automatically created;
2. When the select value is changed, the date will also automatically change, and apply will be called Button click event
3. Click here to preview
4. github Address: 2. Effect display
3. How to use
1. Replace the original
daterangepicker.jsfile.
2. The calling method is the same as before. $('#config-demo').daterangepicker();
4. Code implementation
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 });
The above is the detailed content of Introduction to the extension functions of bootstrap. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Use Bootstrap to implement vertical centering: flexbox method: Use the d-flex, justify-content-center, and align-items-center classes to place elements in the flexbox container. align-items-center class method: For browsers that do not support flexbox, use the align-items-center class, provided that the parent element has a defined height.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use Bootstrap to get the value of the search bar: Determines the ID or name of the search bar. Use JavaScript to get DOM elements. Gets the value of the element. Perform the required actions.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

To verify dates in Bootstrap, follow these steps: Introduce the required scripts and styles; initialize the date selector component; set the data-bv-date attribute to enable verification; configure verification rules (such as date formats, error messages, etc.); integrate the Bootstrap verification framework and automatically verify date input when form is submitted.

Bootstrap provides a simple guide to setting up navigation bars: Introducing the Bootstrap library to create navigation bar containers Add brand identity Create navigation links Add other elements (optional) Adjust styles (optional)
