javascript 从客户端设置剑道日期选择器的最大日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24021668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 02:00:56  来源:igfitidea点击:

set the max date on kendo date picker from client side

javascriptjquerykendo-uidatepicker

提问by GANI

I have this:

我有这个:

var today = new Date();

Updating the kendo datepicker:

更新剑道日期选择器:

$('#datepicker').kendoDatePicker({
    max: today.setDate(today.getDate()+30);
});

In the debugger the max value is 1404408808080but in today variable the date is right one 2014-07-03T17:3. Want to set the max date for kendodatepicker 30 days from the current date.

在调试器中最大值是1404408808080但在今天变量中日期是正确的2014-07-03T17:3。想要将 kendodatepicker 的最大日期设置为距当前日期 30 天。

回答by DontVoteMeDown

You have to use the setOptions()method to change that:

您必须使用该setOptions()方法来更改它:

var datepicker = $("#datepicker").data("kendoDatePicker");

datepicker.setOptions({
    max: new Date(today.setDate(today.getDate()+30))
});

Or if you want just do this in the initialization:

或者,如果您只想在初始化中执行此操作:

$("#datepicker").kendoDatePicker({
    max: new Date(today.setDate(today.getDate()+30))
});

回答by Kylok

The setDatefunction returns the date as an integer (the long number you posted); try sending that as a parameter to a new Date object, like so:

setDate函数以整数形式返回日期(您发布的长数字);尝试将其作为参数发送到新的 Date 对象,如下所示:

$('#datepicker').kendoDatePicker({
    max: new Date(today.setDate(today.getDate()+30));
});

回答by GANI

It worked this way also

它也以这种方式工作

         var today = new Date();
         var maxDate = today.setDate(today.getDate()+30);
         $('#datepicker').kendoDatePicker({
         max: new Date(maxDate) });