【问题标题】:click trigger on bootstrap datepicker jQuery addClass not work在引导日期选择器 jQuery addClass 上单击触发器不起作用
【发布时间】:2015-05-06 06:13:23
【问题描述】:

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

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

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

JSFiddle 上的工作示例

【问题讨论】:

    标签: javascript jquery twitter-bootstrap bootstrap-datepicker


    【解决方案1】:

    你需要使用 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');
        });
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-28
      • 1970-01-01
      • 2017-12-23
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      相关资源
      最近更新 更多