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

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

问题描述

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

上的代码演示

<div class="input-append date" id="datepicker" data-date="02-2012"数据日期格式=mm-yyyy"><input type="text" readonly="readonly" name="date" ><span class="add-on"><i class="icon-th"></i></span>

$("#datepicker").datepicker({视图模式:'年',格式:'mm-yyyy'});

上面的代码运行良好,但我想做的是只允许用户选择月份和年份.

你能告诉我怎么做吗?

解决方案

这个怎么样:

$("#datepicker").datepicker( {格式:mm-yyyy",视图模式:月",minViewMode:月"});

参考:Bootstrap 的日期选择器

<小时>

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

$("#datepicker").datepicker( {格式:mm-yyyy",startView: "月",minViewMode:月"});

另请参阅文档.

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?

解决方案

How about this :

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

Reference : Datepicker for Bootstrap


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

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

Also see the documentation.

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

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