JavaScript Calendar Control Bootstrap-datetimepicker Use Example

Source: Internet
Author: User
Tags pack

In the development of micro-site hotel reservations, in filling out the form of the stay and away from the need to use the Calendar control, before I collected a lot of related JS Calendar control, but now to use is not a suitable, because the development of mobile phone sites, so more picky.
Requirements:
When you click on the entry box for the date form, the text entry box is not ejected, and you cannot enter content into the input box, only the calendar that pops up from the Calendar control picks the date.

Can meet the above requirements of the JS date control, is really rare. In order to find this control, I spent a lot of time ah, finally found the Bootstrap-datetimepicker-master, this is a bootstrap plug-in, look at the development of the document does not seem to help me, or look at the example to explore the tune out, and now share to everyone.
First picture.


Critical Code Snippets

  code is as follows copy code

<div class=" Input-group date form_date "Col-md-5" " Data-date-format= "" "Data-link-field=" Dtp_input2 "data-link-format=" Yyyy-mm-dd "
       <input class= "Form-control" size= "type=" "Text" value= "" READONLY>
      <span class= "Input-group-addon"
      <span class= "Glyphicon" Glyphicon-remove "></span>
      </span>
     <span class= "Input-group-addon"
     <span class= "Glyphicon Glyphicon-calendar" ></span></span>
 </div>


Load related files for calendar controls

<script type= "Text/javascript" src= "/jquery/jquery-1.8.3.min.js" charset= "UTF-8" ></script>
<script type= "Text/javascript" src= "/bootstrap/js/bootstrap.min.js" ></script>
<script type= "Text/javascript" src= "/bootstrap/js/bootstrap-datetimepicker.js" charset= "UTF-8" ></script >
<script type= "Text/javascript" src= "/bootstrap/js/bootstrap-datetimepicker.zh-cn.js" charset= "UTF-8" ></ Script>

Calling code

The code is as follows Copy Code

$ ('. Form_date '). DateTimePicker ({
Language: ' ZH-CN ',/* Load Calendar Language Pack, customizable */
Weekstart:1,
Todaybtn:1,
Autoclose:1,
Todayhighlight:1,
Startview:2,
Minview:2,
forceparse:0
});
</script>


The Bootstrap-datetimepicker-master Calendar control is international, so there are language packs for countries and regions, The Language pack directory is bootstrap-datetimepicker-masterbootstrap-datetimepicker-masterjslocales, such as China's language pack path is bootstrap-datetimepicker-masterbootstrap-datetimepicker-masterjslocalesbootstrap-datetimepicker.zh-cn.js

The code is as follows:

The code is as follows Copy Code
/**
* Simplified Chinese translation for Bootstrap-datetimepicker
* Yuan Cheung <advanimal@gmail.com>
*/
;(function ($) {
$.fn.datetimepicker.dates[' ZH-CN '] = {
Days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
Daysshort: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
Daysmin: ["Day", "one", "two", "three", "four", "five", "six", "Day"],
Months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
Monthsshort: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
Today: "The Day",
Suffix: [],
Meridiem: ["Morning", "Afternoon"],
Format: "YYYY-MM-DD"/* control display format, default is empty, show hours/minutes
};
} (JQuery));

Of course, you can also customize the language side package, very convenient.

Complete example Baidu network disk download Http://pan.baidu.com/s/1hqoW8z6

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.