使用javascript动态修改datetimepicker [英] modify datetimepicker dynamically with javascript

查看:493
本文介绍了使用javascript动态修改datetimepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将datetimepicker初始化为

I am initializing a datetimepicker as

$(document).ready(function() {
    $("#meeting_datetime").datetimepicker({format: 'LLLL', stepping: 5, enabledHours: [], daysOfWeekDisabled: []}).prop('disabled', true);
});

现在,我想启用此datetimepicker并根据用户输入动态限制可能的选择。每当用户更改某些其他选择时,我都会调用此函数

Now I would like to enable this datetimepicker and limit the possible selection dynamically depending on user input. I call this function everytime the user changes certain other selections

$("#meeting_datetime").datetimepicker({defaultDate: tomorrowsDate, format: 'LLLL', enabledHours: meeting_time_moment.hours(), stepping: 5, daysOfWeekDisabled: weekday_unchecked_value}).prop('disabled', false);

此函数唯一有效的方面是最后的disable false语句。 datetimepicker确实可以编辑。但是,daysOfWeekDisabled函数根本不起作用。我输入的是这样

The only aspect of this function which works is the disable false statement at the end. The datetimepicker does indeed become editable. However, the daysOfWeekDisabled function doesn't work at all. I am inputting something like this

weekday_unchecked_value =  [0, 1, 3, 4, 5, 6]

当我在初始化步骤中执行此操作时(第一个代码在顶部被截断),它工作正常,但更新不起作用似乎有效。有刷新功能或其他功能吗?我看了一下文档( https://eonasdan.github.io/bootstrap-datetimepicker/),但我找不到它...

when I do this in the initialization step (first code snipped on the top), it works fine, but the update does not seem to work. Is there a refresh function or anything? I had a look at the docs (https://eonasdan.github.io/bootstrap-datetimepicker/), but I couldn't find it...

推荐答案

我找到了解决方案...只使用函数

I found the solution... just use the functions instead

$("#meeting_datetime").data("DateTimePicker").daysOfWeekDisabled(weekday_unchecked_value)
$("#meeting_datetime").data("DateTimePicker").enabledHours([meeting_time_moment.hours()])
$("#meeting_datetime").data("DateTimePicker").stepping(60)

在我看来,应该有一个更简单的方法,但这是快速的并且可以正常工作...

it seems to me that there should be an easier way, but this is quick and works fine...

这篇关于使用javascript动态修改datetimepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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