检测Bootstrap Datetimepicker对输入字段所做的更改

时间:2022-06-01 00:07:34

I set my input field so that when user clicks on it, a Bootstrap Datetimepicker is shown. I want to calculate something based on the date that is being entered in that input field through the datetimepicker.

我设置了我的输入字段,以便当用户点击它时,会显示一个Bootstrap Datetimepicker。我想根据通过datetimepicker在输入字段中输入的日期来计算某些内容。

I have thus defined my calculating function as:

因此我将计算函数定义为:

$("#dob").on("input change bind", function (e) {
        //calculate age here.
    });

"dob" is the id for the input box. Datetimepicker correctly enters the datetime to the field. Code:

“dob”是输入框的id。 Datetimepicker正确地将日期时间输入到字段中。码:

$('#dob').datetimepicker({
            format: 'YYYY-MM-DD',
            showClose: true
        });

Curiously, this bit of code works if I manually enter the date

奇怪的是,如果我手动输入日期,这段代码就可以工作

$("#dob").change( function () {
        alert('DOB');
    });

But it is not called when the date is selected through Bootstrap Datetimepicker. What's causing the problem here?

但是,通过Bootstrap Datetimepicker选择日期时不会调用它。是什么原因引起了这个问题?

1 个解决方案

#1


1  

try

尝试

$('#dob').change(function () { //OR $('#dob').on('change',function ()
    console.log($('#date-daily').val());
});

UPDATE

UPDATE

$('#dp3').datepicker().on('changeDate', function (ev) {
    $('#dob').change();
});
$('#dob').change(function () {
    console.log($('#dob').val());
});

#1


1  

try

尝试

$('#dob').change(function () { //OR $('#dob').on('change',function ()
    console.log($('#date-daily').val());
});

UPDATE

UPDATE

$('#dp3').datepicker().on('changeDate', function (ev) {
    $('#dob').change();
});
$('#dob').change(function () {
    console.log($('#dob').val());
});