jQuery UI-Datepicker-隐藏年份 [英] jQuery UI - Datepicker - Hide year

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

问题描述

我正在使用jQuery UI 1.8,我想在弹出窗口和文本框中都向用户隐藏年份.从本质上讲,我希望用户只选择日期和月份,而不是选择日期,月份和年份.

I'm using jQuery UI 1.8 and I would like to hide the year from the user in both the popup and the textbox. Essentially instead of picking the day, month and year I want the user to just pick the day and month.

将年份隐藏在文本框中很容易,下面显示的代码将做到这一点.我很困惑如何在弹出窗口中隐藏年份-因此它会说"April"而不是"2010年4月".

Hiding the year in the textbox is easy enough, the code shown below will do that. I'm stumped on how to hide the year from the popup - so it would say "April" instead of "April 2010".

$(function() {
        $("#beginDateRange").datepicker({ dateFormat: 'mm/dd' });
});

<input type="text" name="beginDateRange" id="beginDateRange" />

任何帮助将不胜感激.

推荐答案

我不认为此选项是通过api公开的. 我相信最简单的方法是更改​​样式表. 将ui-datepicker-year类更改为display: none 另一个选择是编辑源,以便根本不渲染它, 为此,您可以删除此部分代码:

I dont think this option is exposed va the api. I belive that the easiest way is to change the stylesheet. Change the ui-datepicker-year class to display: none Another option would be to edit the source so it isnt rendered at all, to do that you can remove this part of the code:

 // year selection
if (secondary || !changeYear)
html += '<span class="ui-datepicker-year">' + drawYear + '</span>';
else {
// determine range of years to display
var years = this._get(inst, 'yearRange').split(':');
var thisYear = new Date().getFullYear();
var determineYear = function(value) {
var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) :
(value.match(/[+-].*/) ? thisYear + parseInt(value, 10) :
parseInt(value, 10)));
return (isNaN(year) ? thisYear : year);
};
var year = determineYear(years[0]);
var endYear = Math.max(year, determineYear(years[1] || ''));
year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
html += '<select class="ui-datepicker-year" ' +
'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'Y\');" ' +
'onclick="DP_jQuery_' + dpuuid + '.datepicker._clickMonthYear(\'#' + inst.id + '\');"' +
'>';
for (; year <= endYear; year++) {
html += '<option value="' + year + '"' +
(year == drawYear ? ' selected="selected"' : '') +
'>' + year + '</option>';
}
html += '</select>';
}

我还没有尝试删除代码,但是它应该可以工作. 我确实尝试使用css隐藏它,并且确实起作用了(无论如何在firefox中:))

I haven't tried removing the code but it should work. I did try hiding it using css and that does work (in firefox anyway :) )

HTH

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

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