单击 bootstrap 日期选择器 jQuery addClass 上的触发器无效

click trigger on bootstrap datepicker jQuery addClass not work

我正在使用 bootstrap DatePciker ,我想在几天 (td) 添加一个点击事件,当我点击任何一天时,将 class 添加到那一天 (td)。但它不起作用。

$('#calendar').datepicker({
    multidate: true,
    todayHighlight: true,
    todayBtn: true
});

$('tbody').on('click','td.day',function(e){
    e.preventDefault();
    $(this).addClass('clicked');
});

JSFiddle

上的工作示例

您需要使用 changeDate datePicker 事件。

文档:http://bootstrap-datepicker.readthedocs.org/en/latest/events.html

$('#calendar').datepicker('setDates', events)
    .on('changeDate', function (e) {
        // $(this).addClass('clicked'); // $(this) here is not what you think.
        $('.active').addClass('clicked');
    });

演示:http://jsfiddle.net/2L1ovhbm/13/