admin管理员组

文章数量:1277529

How to get current viewMode property from "Bootstrap Datepicker"? I initialize the control with viewMode= 'years' and I want to close datepicker on changeDate event, only when viewMode='days'.

The user selects a year, then a month, and finally a day. In that moment the control must be closed.

This is the code:

$("#date").datepicker(
    {viewMode: 'years',
     format: 'dd/mm/yyyy'
});

$('#date').on('changeDate', function (ev) {
    //close when viewMode='0' (days)
})

Can anyone help?

How to get current viewMode property from "Bootstrap Datepicker"? I initialize the control with viewMode= 'years' and I want to close datepicker on changeDate event, only when viewMode='days'.

The user selects a year, then a month, and finally a day. In that moment the control must be closed.

This is the code:

$("#date").datepicker(
    {viewMode: 'years',
     format: 'dd/mm/yyyy'
});

$('#date').on('changeDate', function (ev) {
    //close when viewMode='0' (days)
})

Can anyone help?

Share Improve this question edited Feb 22, 2013 at 16:43 Gonzalo asked Jan 22, 2013 at 11:20 GonzaloGonzalo 2,8767 gold badges31 silver badges42 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

Check this : http://jsfiddle/nAXnM/

HTML

    <input type="text" class="span2" value="02/16/12" data-date-format="mm/dd/yy" id="dp2" >

JS

$("#dp2").datepicker({
 viewMode: 'years',
 format: 'dd/mm/yyyy'
});

$('#dp2').on('changeDate', function (ev) {
   //close when viewMode='0' (days)
   if(ev.viewMode === 'days'){
      $('#dp2').datepicker('hide');
   }
})

If you're using the forked version of Bootstrap Datepicker, to close the UI widget when a date is selected, set the autoclose option to true:

$("#date").datepicker({
    autoclose: true
});

本文标签: javascriptHow to get current viewMode property from quotBootstrap DatepickerquotStack Overflow