Jquery datepicker - 只有日和月

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6799092/
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-08-26 21:23:59  来源:igfitidea点击:

Jquery datepicker - only day and month

jqueryjquery-uidatepickerjquery-ui-datepicker

提问by tanon

I want the user to specify their birthday or anniversary date (without year) in a form. For this, I want to use jquery datepicker but it should not show any year option at all. How to do it?

我希望用户在表单中指定他们的生日或周年纪念日(不含年份)。为此,我想使用 jquery datepicker,但它根本不应该显示任何年份选项。怎么做?

I tried modifying the code in this so questionby making changeDay: trueand changeYear: falsebut could not get it to work.

我试图修改代码这个问题,所以通过使changeDay: truechangeYear: false,但它不能去工作。

采纳答案by Emil Condrea

set the css to hide the year and the dateFormat as K6t said

设置 css 以隐藏年份和日期格式,如 K6t 所说

.ui-datepicker-year{
    display:none;
}

回答by Nicola Peluchetti

You could do:

你可以这样做:

$('#date').datepicker( {
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        dateFormat: 'dd MM'
    });

fiddle http://jsfiddle.net/u8GnD/1/

小提琴http://jsfiddle.net/u8GnD/1/

回答by Rafi

You can hide year from a datepicker like this :

您可以像这样从日期选择器中隐藏年份:

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

It wont affect to other datepickers in same page.

它不会影响同一页面中的其他日期选择器。

回答by Vivek Chaudhari

$("#datepicker").datepicker( {
format: "dd-MM",
viewMode: "months", 
maxViewMode: "months"
});

this will surely hide year from datepicker view, will show only month and dayspanel

这肯定会从日期选择器视图中隐藏年份,只会显示月份和日期面板

回答by Sohail

$( function() {
     var date = $('#datepicker').datepicker({
        dateFormat: 'yy-mm-dd',
        changeMonth: true, 
        changeYear: false}).val();
});

回答by K6t

change dateFormat as

将日期格式更改为

dateFormat: 'dd MM',

in datePicker.js file

在 datePicker.js 文件中