如何禁用jQuery datepicker中的月份选择? [英] How can I disable month selection in the jQuery datepicker?

查看:78
本文介绍了如何禁用jQuery datepicker中的月份选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试禁用允许用户更改月份的左/右按钮。我已经删除了几个月的下拉列表,但无法删除按钮。

I am trying disable the left/right buttons that allow the user to change months. I've removed the drop down list of months but can't get rid of the buttons.

$("#date").datepicker({
    changeMonth: false,
    changeYear: false,
    dateFormat: 'dd/mm/yy',
    duration: 'fast'
});


推荐答案

您可以使用 stepMonths ,方法是单击它们使它们无处可见,例如:

You can effectively disable them using stepMonths by making them go nowhere when clicked, like this:

$("#date").datepicker({
  changeMonth: false,
  changeYear: false,
  dateFormat: 'dd/mm/yy',
  duration: 'fast',
  stepMonths: 0
});

您可以在这里尝试

或者,您可以删除以下按钮:

Or, you could remove the buttons like this:

$("#date").datepicker({
  changeMonth: false,
  changeYear: false,
  dateFormat: 'dd/mm/yy',
  duration: 'fast'
}).focus(function() {
  $(".ui-datepicker-prev, .ui-datepicker-next").remove();
});​

您可以在此处尝试,因为默认的 showOn 选项是 focus ,如果您使用的是其他事件,只需在 .datepicker() $ c>调用(因此其事件首先运行,您无法隐藏尚未创建的内容)。

You can give that a try here, this works because the default showOn option is focus, if you're using a different event, just bind to that after the .datepicker() call (so its event runs first, you can't hide what isn't created yet).

这篇关于如何禁用jQuery datepicker中的月份选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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