简体   繁体   English

在Jquery Datepicker中动态更改突出显示的日期

[英]Dynamically change highlighted dates in Jquery Datepicker

hi I have a Jquery Datepicker object that is created fine with no highlighted dates and a particular minDate. 嗨,我有一个很好的Jquery Datepicker对象,没有突出显示的日期和特定的minDate。

I want to add a highlights to this datepicker based on an AJAX call made by the user, but the only way I can see to change the highlights is adding a function to the beforeShowDay event, which is set on setup. 我想根据用户进行的AJAX调用向该日期选择器添加一个突出显示,但是我看到的更改突出显示的唯一方法是向beforeShowDay事件添加一个函数,该事件是在设置时设置的。

How can I change this function on an existing datepicker and force it to redraw so that I get my new date(s) to be highlighted. 如何在现有的日期选择器上更改此功能,并强制其重绘,以便突出显示新日期。

Many thanks everyone. 非常感谢大家。

Dave 戴夫

Right the only way I could find to do this is to use the destroy method then redraw the picker with the new method attached to it. 对,我能找到的唯一方法是使用destroy方法,然后使用附加的新方法重新绘制选择器。 If anyone knows a better way of doing this please add it and I'll give you the answer. 如果有人知道更好的方法,请添加它,我会给你答案。 Thanks 谢谢

EDIT: Code... 编辑:代码...

Setup the picker... 设置选择器...

    var datePickerSettings = {
        beforeShowDate: beforeShowDateMethod
    };

    var alternateDatePickerSettings = {
        beforeShowDate: beforeShowDateMethodAlternate
    };

    $('#mydiv').datepicker(datePickerSettings);

Then once callback is complete 然后,一旦回调完成

 $('#mydiv').datepicker('destroy')
 $('#mydiv').datepicker(alternateDatePickerSettings);

In the end I didn't use the date picker as the requirements changed, but this should solve the problem 最后,随着需求的变化,我没有使用日期选择器,但这应该可以解决问题

Dave 戴夫

There is the setDate method of the datepicker. 有日期选择器的setDate方法。 I cannot link directly but it is here http://jqueryui.com/demos/datepicker/ under methods 我无法直接链接,但方法在此处http://jqueryui.com/demos/datepicker/

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

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