jquery bootstrap datepicker only month and day

馋奶兔 提交于 2021-01-29 17:29:55

问题


i have example

http://jsfiddle.net/rAdV6/20/?

in jqueryui datepicker

third demo example

where is only month and date.

i want this on bootstrap datepicker.

<http://www.eyecon.ro/bootstrap-datepicker/>?

回答1:


The only workaround that I have made for this is to remove the year from the date title before the datepicker show. Below is the code I used to initialize the datepicker:

$(".datepicker").datepicker({
    format : 'MM dd',
}).on('show', function() {
    // remove the year from the date title before the datepicker show
    var dateText  = $(".datepicker-days .datepicker-switch").text();
    var dateTitle = dateText.substr(0, dateText.length - 5);
    $(".datepicker-days .datepicker-switch").text(dateTitle);
});



回答2:


This is what works for me. Using jQuery split function.

$(".datepicker").datepicker({
    format : 'MM dd',
}).on('show', function() {
    // remove the year from the date title before the datepicker show
        var dateText  = $(".datepicker-days .datepicker-switch").text().split(" ");
        var dateTitle = dateText[0];
        $(".datepicker-days .datepicker-switch").text(dateTitle);
        $(".datepicker-months .datepicker-switch").css({"visibility":"hidden"});
});



回答3:


The bootstrap datepicker module is a third party tool which you need to download, install and reference from your code.

Download the javascript library from http://www.eyecon.ro/bootstrap-datepicker/.

All you need to do is add the following line of code and then it works.

$('.datepicker').datepicker({
    format: "mm/dd"
})`



回答4:


In Jquery datepicker you can do something like this :

$(".daypicker").datepicker( { 
    changeYear: false, 
    dateFormat: 'MM-dd',
}).focus(function () {
    $(".ui-datepicker-year").hide();
});

It wont affect to other datepickers in same page.




回答5:


Use this:

format: "dd/mm",
weekStart: 1,
startView: 1,
maxViewMode: 1,
autoclose: true


来源:https://stackoverflow.com/questions/21824696/jquery-bootstrap-datepicker-only-month-and-day

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!