twitter-bootstrap 如何从“Bootstrap Datepicker”获取当前的 viewMode 属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14457380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 16:10:31  来源:igfitidea点击:

How to get current viewMode property from "Bootstrap Datepicker"

javascriptjquerytwitter-bootstrapdatepicker

提问by Gonzalo

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

如何viewMode从“Bootstrap Datepicker”获取当前属性?我用 初始化控件,viewMode= 'years'我想在changeDate事件上关闭日期选择器,仅当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?

任何人都可以帮忙吗?

回答by Praveen Vijayan

Check this : http://jsfiddle.net/nAXnM/

检查这个:http: //jsfiddle.net/nAXnM/

HTML

HTML

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

JS

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');
   }
})

回答by Sam

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

如果您使用的是 Bootstrap Datepicker 的分叉版本,要在选择日期时关闭 UI 小部件,请将autoclose选项设置为true

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