如何使用字符串为 jQueryUI Datepicker 设置 minDate/maxDate? [英] How can I set the minDate/maxDate for jQueryUI Datepicker using a string?

查看:24
本文介绍了如何使用字符串为 jQueryUI Datepicker 设置 minDate/maxDate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQueryUI Datepicker 文档 指出可以使用a当前日期格式中的字符串".所以我尝试了以下方法来初始化日期选择器:

jQueryUI Datepicker documentation states that the minDate option can be set using "a string in the current dateFormat". So I've tried the following to initialize datepickers:

$("input.date").datepicker({ minDate: "01/01/2010", maxDate: "12/31/2010" });

然而,这会导致我的日期选择器有一个可选择的日期范围,从 11/06/2015 到 12/17/2015.

However, this results in my datepicker having a selectable date range that goes from 11/06/2015 to 12/17/2015.

我已经检查了当前的日期格式和它的 mm/dd/yy,这应该是表示月份的 2 位数字,日的 2 位数字,年的 4 位数字,用斜线分隔.我还尝试在初始化语句中包含 dateFormat: "mm/dd/yy".

I've checked the current dateformat and its mm/dd/yy, which is supposed to mean 2 digits for the month, 2 for the day, and 4 for the year, separated by slashes. I've also tried including dateFormat: "mm/dd/yy" in the inizialization statement.

之后我还检查了 minDate 和 maxDate 的值,它们被设置为我想要的值:01/01/201012/31/2010.

I've also checked the values for minDate and maxDate afterwards and they ARE being set to the values I want: 01/01/2010 and 12/31/2010.

我希望能够使用字符串设置 min/maxDate,因为我从其他地方将这些值作为字符串传递.也许有人知道为什么会发生这种情况以及如何解决这个问题,或者是一种解决方法来实现这一点,也许会改变日期字符串的格式或其他什么?

I want to be able to set min/maxDate with strings because I'm being passed these values as strings from somewhere else. Maybe someone knows why this happens and how to solve this, or a workaround to achieve this, perphaps changing the format of the date strings or something?

谢谢

使用:jQuery v1.3.2jQuery UI v1.7.2

推荐答案

最后我不得不使用这样的东西,因为 v1.7 datepicker 没有日期问题:

In the end I had to use something like this, since the v1.7 datepicker has no probs with Dates:

$.getJSON("/GetMinMaxDates/", function(dates) {
    var DateLimits = {min:null, max:null};

    DateLimits.min = new Date(Date.parse(dates.min));
    DateLimits.max = new Date(Date.parse(dates.max));

    $("input.date").datepicker({ dateFormat: "mm/dd/yy", minDate: DateLimits.min, maxDate: DateLimits.max });
});

这篇关于如何使用字符串为 jQueryUI Datepicker 设置 minDate/maxDate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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