How to limit the selectable time range of date picker in bootstrap? (code example)

青灯夜游
Release: 2020-12-08 11:05:25
forward
3283 people have browsed it

bootstrapHow to limit the selectable time range of the date picker? The following article will introduce the method to you. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

How to limit the selectable time range of date picker in bootstrap? (code example)

Recommended related tutorials: "bootstrap tutorial"

1. Application scenarios

In actual applications, data within a certain date range may be queried based on the date field, and the optional time of the date selector needs to be limited.

For example: the start time cannot be greater than the end time , the end time cannot be less than the start time. At this time, the values of startDate and endDate must be dynamically set for the start date selector and end date selector.

2. Related knowledge points

1. Initialization of bootstrap-datepicker

Introduce bootstrap-datepicker.js and bootstrap -datepicker.css

Understanding of bootstrap-datepicker configuration parameters

2. boostrap-datepicker's changeDate event: triggered when the date changes

3. bootstrap-datepicker's setEndDate and setStartDate method

4. For detailed configuration, please refer to the official document http://bootstrap-datepicker.readthedocs.org/en/latest/methods.html

3. Application examples

1. In JSP, declare the date picker

最后接入时间
Copy after login

2. In JS, initialize and configure the date picker

 //开始时间: $('#qBeginTime').datepicker({ todayBtn : "linked", autoclose : true, todayHighlight : true, endDate : new Date() }).on('changeDate',function(e){ var startTime = e.date; $('#qEndTime').datepicker('setStartDate',startTime); }); //结束时间: $('#qEndTime').datepicker({ todayBtn : "linked", autoclose : true, todayHighlight : true, endDate : new Date() }).on('changeDate',function(e){ var endTime = e.date; $('#qBeginTime').datepicker('setEndDate',endTime); });
Copy after login

3. Rendering

For more programming-related knowledge, please visit:Programming Learning Website! !

The above is the detailed content of How to limit the selectable time range of date picker in bootstrap? (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!