我正在使用datepicker 。绑定(bind)事件的常用方法(例如 beforeShowDay
)是:
$('.selector').datepicker({
beforeShowDay: function(date) { ... }
});
我需要的是在渲染日历后绑定(bind) beforeShowDay
事件。所以,首先我要渲染日历:
$('.mySpecialContainer').datepicker({
//in this moment, for some reason, I am not allowed to bind nothing (that's not me who renders the calendar, that's why I am not allowed)
});
然后,如果我尝试以通常的方式绑定(bind)某些内容:
$('.mySpecialContainer').datepicker({
beforeShowDay: function(date) { ... }
});
当然,日历将在'.mySpecialContainer'
内再次呈现,而不仅仅是绑定(bind)事件。我尝试过:
$('.mySpecialContainer').bind('beforeShowDay', function(date) { ... });
但这只是绝望的举动:)
最佳答案
我不明白为什么你不能在特定的 datepicker
事件上调用 bind
(或者,就此而言,大多数 datepicker
事件)。大多数其他 jQueryUI 小部件允许事件的后期绑定(bind)。
但是,您可以尝试以下操作。 hasDatepicker
应用于日期选择器,并且在这些元素上再次调用 .datepicker
并不是重新初始化小部件,它只是修改一个选项:
$('.hasDatepicker').datepicker("option", "beforeShowDay",
function(date) { ... });
关于JQuery UI 日期选择器 : how to bind an event AFTER the calendar was rendered?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5201367/