Introduction to the date range selection and bootstrapdatepicker of Bootstrap

Source: Internet
Author: User

Introduction to the date range selection and bootstrapdatepicker of Bootstrap

There is often a need to use the date plug-in. Select two input boxes. The start time is earlier than the end time. The End Time is later than the start time. the start time and end time are not later than the current time.

Of course, we can use the selected result to determine whether the input is correct or not. But the better way is to make some restrictions on our date selection plug-in.

Bootstrap works with an excellent date selection plug-in. DatePicker and DateTimePicker.

The two functions are similar. The usage is similar. DatePicker supports more events and settings.

When the api knows the date change, there will be an event changeDate. When the selected date changes, we will call the callback for this event. Unfortunately, this event does not appear to be triggered when we enter or delete a date in the input box. Therefore, you can add the readonly attribute to the input box. Read-Only status, and a clear button is provided for the date control. In this case, only the date plug-in is used to control the changes of the date.

However, when the DateTimePicker plug-in is used to click the Clear button, the following error occurs: Uncaught TypeError: Cannot read property 'gettime' of null. As a result, the changeDate event Cannot be used normally.

So use the DatePicker plug-in.

Then, when the date of an input box changes (including clearing), The changeDate event is triggered and the optional range of another input box is modified in its callback function.

In addition, to display Chinese characters on the interface, DatePicker also needs to load css. Bootstrap-datepicker.zh-CN.min.js.

The following code is used:

Function DatePicker (beginSelector, endSelector) {// select only the date $ (beginSelector ). datepicker ({language: "zh-CN", autoclose: true, startView: 0, format: "yyyy-mm-dd", clearBtn: true, todayBtn: false, endDate: new Date ()}). on ('changedate', function (ev) {if (ev. date) {$ (endSelector ). datepicker ('setstartdate', new Date (ev. date. valueOf ()} else {$ (endSelector ). datepicker ('setstartdate', null) ;}} $ (endSelector ). datepicker ({language: "zh-CN", autoclose: true, startView: 0, format: "yyyy-mm-dd", clearBtn: true, todayBtn: false, endDate: new Date ()}). on ('changedate', function (ev) {if (ev. date) {$ (beginSelector ). datepicker ('setenddate', new Date (ev. date. valueOf ()} else {$ (beginSelector ). datepicker ('setenddate', new Date () ;}} DatePicker ("# date_begin", "# date_end ");

Bootstrap DatePicker: the start date and end date are not later than the end time, And the start date and end date are not later than the current date.

The above is a small Editor for you to talk about how to choose all the content of the date range of Bootstrap DatePicker ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.