【问题标题】:bootstrap datepicker: run function when date is changed引导日期选择器:日期更改时运行功能
【发布时间】:2016-02-07 12:40:40
【问题描述】:

当用户使用日期选择器更改日期输入值时,我想运行一个函数,这是我的代码:

The datepicker used.

html:

<div class="input-group date form-group" data-provide="datepicker">
    <input type="text" class="form-control" id="birthdate" 
            name="birthdate" placeholder="Student Birth Date...">
    <div class="input-group-addon">
        <span class="glyphicon glyphicon-th"></span>
    </div>
</div>

js:

$('#birthdate').datepicker({
    format: 'yyyy/mm/dd',
    startDate: '-3d'
});

$('#birthdate').datepicker()
    .on('changeDate', function(e) {
        alert();
});

更改日期后,什么也没发生。我在问之前已经搜索过这个问题,但没有答案能解决我的问题!

【问题讨论】:

    标签: jquery twitter-bootstrap datepicker bootstrap-datepicker


    【解决方案1】:

    尝试使用“更改事件”

    演示:http://jsfiddle.net/Z3CRA/99/

    $('#birthdate').datepicker({
        format: 'yyyy/mm/dd',
        startDate: '-3d'
    });
    
    
    $( "#birthdate" ).change(function() {
      alert( "Handler for .change() called." );
    });
    

    更新:您应该选择 div#datepicker 而不是直接输入。

    演示:http://jsfiddle.net/8ac7b7Lh/4/

    $('#datepicker').datepicker({
        format: 'yyyy/mm/dd',
        startDate: '-3d'
    });
    
    $('#datepicker').datepicker().on('changeDate', function (ev) {
      console.log('Input changed');
    });
    

    【讨论】:

    猜你喜欢
    • 2019-08-23
    • 2013-11-28
    • 1970-01-01
    • 1970-01-01
    • 2013-09-05
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多