简体   繁体   English

jQuery Datepicker-动态更改可选日期

[英]jQuery Datepicker - Dynamically change selectable dates

I am using the jQuery datepicker and I currently have this code: 我正在使用jQuery datepicker,目前有以下代码:

$("#dateObj").datepicker({
    beforeShowDay: findDateAvailable
});

where findDateAvailable is a function which checks if the date is in an array and if not, makes the date not selectable. 其中findDateAvailable是用于检查日期是否在数组中的函数,如果不是,则使日期不可选择。

My question is: how do I change which dates are 'active' and can be selected without changing my array and then re-creating the datepicker object? 我的问题是:如何更改哪些日期是“有效的”并且可以在不更改数组的情况下选择日期,然后重新创建datepicker对象?

You can use the refresh method of the datepicker widget. 您可以使用datepicker小部件的refresh方法。

Redraw the date picker, after having made some external modifications. 进行一些外部修改后,重新绘制日期选择器。 This method does not accept any arguments. 此方法不接受任何参数。

Reference here: http://api.jqueryui.com/datepicker/#method-refresh 参考此处: http : //api.jqueryui.com/datepicker/#method-refresh

You can use it in your script by using: 您可以通过以下方式在脚本中使用它:

$("#dateObj").datepicker("refresh");

Working fiddle: http://jsfiddle.net/ChM6D/2/ 工作提琴: http : //jsfiddle.net/ChM6D/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM