嗨,我确定必须有一个简单的方法来做到这一点,但无法找到任何设置它的选项。jQuery datepicker,禁用月份选择
我想禁用允许用户更改月份的左/右按钮。我已经删除了几个月的下拉列表,但无法摆脱按钮。
$("#date").datepicker({
changeMonth: false,
changeYear: false,
dateFormat: 'dd/mm/yy',
duration: 'fast'
});
嗨,我确定必须有一个简单的方法来做到这一点,但无法找到任何设置它的选项。jQuery datepicker,禁用月份选择
我想禁用允许用户更改月份的左/右按钮。我已经删除了几个月的下拉列表,但无法摆脱按钮。
$("#date").datepicker({
changeMonth: false,
changeYear: false,
dateFormat: 'dd/mm/yy',
duration: 'fast'
});
可以有效地禁止他们使用stepMonths
,使它们无处可去点击的时候,是这样的:
$("#date").datepicker({
changeMonth: false,
changeYear: false,
dateFormat: 'dd/mm/yy',
duration: 'fast',
stepMonths: 0
});
或者,你可以删除这样的按钮:
$("#date").datepicker({
changeMonth: false,
changeYear: false,
dateFormat: 'dd/mm/yy',
duration: 'fast'
}).focus(function() {
$(".ui-datepicker-prev, .ui-datepicker-next").remove();
});
You can give that a try here,t他的作品,因为默认showOn
选项是focus
,如果您使用的是其他事件,只需在调用.datepicker()
后绑定到(因此它的事件首先运行,您不能隐藏尚未创建的内容)。
我不知道如何直接在jQuery中完成它(或者如果可能的话)。
但是,如果你找不到在那里做的方法,你总是可以隐藏在CSS按钮。
你想要的CSS选择器(从内存中,所以你可能需要检查)
.ui-datepicker .ui-datepicker-prev,
.ui-datepicker .ui-datepicker-next
{
display:none;
}
所提到的解决方案并没有为我工作,我developped这样的:
$('#datepicker').find('.ui-datepicker-next').remove();
$('#datepicker').find('.ui-datepicker-prev').remove();
这是我的方式使datepicker选择只有一年:
if (document.styleSheets[0].addRule) {
document.styleSheets[0].addRule(".ui-datepicker-calendar", "display: none;");
else {
document.styleSheets[0].insertRule(".ui-datepicker-calendar {display: none;}", 0);
}
.datepicker({
dateFormat: 'yy',
showMonthAfterYear: false,
changeMonth: false,
changeYear: true,
showButtonPanel: true,
stepMonths: 12,
monthNames: ["", "", "", "", "", "", "", "", "", "", "", "", "", ""],
onChangeMonthYear: function (year) {
$(this).val(year);
}
});
感谢尼克,他们都做了伎俩,但去除了按钮alltog醚。 – JBoom 2010-08-19 08:35:46