我正在使用 bootstrap DatePciker ,我想在几天 (td) 添加一个 Click 事件,当我点击任何一天时,将类(class)添加到那一天 (td)。但它不起作用。
$('#calendar').datepicker({
multidate: true,
todayHighlight: true,
todayBtn: true
});
$('tbody').on('click','td.day',function(e){
e.preventDefault();
$(this).addClass('clicked');
});
关于 JSFiddle 的工作示例
最佳答案
您需要使用 datePicker 的 changeDate
事件。
文档: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');
});
关于javascript - 在 bootstrap datepicker jQuery addClass 上单击触发器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30068892/