简体   繁体   中英

How to Display year only Calendar?

I am using Predefined bootstrap calendar in my page. Its working Properly, but for few text box I need to display year only calendar.

My Codes are

<!-- bootstrap datepicker -->
    <link rel="stylesheet" href="~/Content/adminlte/components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">


 <!-- bootstrap datepicker -->
    <script src="~/Content/adminlte/components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>

 <script>
        $(function () {

            $('#Date').datepicker({
                autoclose: true
            })
        })</script>

Design

  <label>Date</label>
  <div class="input-group date">
 <input type="text" class="form-control pull-right" id="Date">
 <div class="input-group-addon">
 <i class="fa fa-calendar"></i>
 </div>
 </div>

My datpicker with text box image as follows

在此处输入图片说明

Its working fine to pickup a date. But for few text box I need year only option as shown in image below

在此处输入图片说明

If I use code from some other stackoverflow answers or from this link code , it affect my date picker design and it also change the option for all text boxes to choose normal date also... Kindly help.. TIA.

use this config options :

$("#Date").datepicker({
    autoclose: true,
    format: "yyyy",
    viewMode: "years", 
    minViewMode: "years"
});

Look if you go to jquery page and searched for calender. They will tell you the properties for calender format and how to use them and thus you copy and paste thrm in your bootstrap calender since it will be the same. Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM