jQuery datepicker,禁用月份选择 [英] jQuery datepicker, disable month selection

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

问题描述

我敢肯定必须有一种简单的方法来做到这一点,但找不到在任何地方进行设置的选项.

Hi i'm sure there must be an easy way to do this but can't find the option to set it anywhere.

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

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()调用之后绑定到该 (因此其事件首先运行,您无法隐藏尚未创建的事件)

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天全站免登陆