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

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

问题描述

jQueryUI Datepicker 文档指出可以使用"a"设置minDate选项.当前dateFormat中的字符串".因此,我尝试了以下方法来初始化日期选择器:

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" });

但是,这导致我的日期选择器具有从2015年6月11日到2015年12月17日的可选日期范围.

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位数字,并用斜杠分隔.我还尝试过在inizialization语句中包含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.2 jQuery 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天全站免登陆