Bootstrap Datepicker-仅限月份和年份 [英] Bootstrap Datepicker - Months and Years Only

查看:100
本文介绍了Bootstrap Datepicker-仅限月份和年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用引导日期选择器,我的代码如下所示, jsfiddle

I am using bootstrap datepicker and my code is like following, Demo of the code on jsfiddle

<div class="input-append date" id="datepicker" data-date="02-2012" 
     data-date-format="mm-yyyy">

 <input  type="text" readonly="readonly" name="date" >    
 <span class="add-on"><i class="icon-th"></i></span>      
</div>      


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

上面的代码工作正常,但是我想做的是允许用户只选择月份和年份.

The above code is working fine, but what I am trying to do is allow users pick months and years only.

您能告诉我该怎么做吗?

Could you please tell me how to do that?

推荐答案

如何解决这个问题:

$("#datepicker").datepicker( {
    format: "mm-yyyy",
    viewMode: "months", 
    minViewMode: "months"
});

参考文献: Bootstrap的日期选择器

对于1.2.0及更高版本,viewMode已更改为startView,因此请使用:

For version 1.2.0 and newer, viewMode has changed to startView, so use:

$("#datepicker").datepicker( {
    format: "mm-yyyy",
    startView: "months", 
    minViewMode: "months"
});

另请参见文档.

这篇关于Bootstrap Datepicker-仅限月份和年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆