Bootstrap DatePicker-Onchange [英] Bootstrap DatePicker - Onchange

查看:851
本文介绍了Bootstrap DatePicker-Onchange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Bootstrap 3 Datepicker 插件.当用户选择日期时,我想更新UI的各个部分.我基本上是在尝试创建一个在日期更改时调用的函数.但是,我的尝试一直没有成功.目前,我正在尝试以下

I am using the Bootstrap 3 Datepicker plugin. When the user chooses a date, I want to update various parts of my UI. I'm basically trying to create a function that is called when the date changes. However, I've been unsuccessful in my attempts. Currently, I'm trying the following

$('#myDatePicker').datetimepicker({
  change: function() {
    alert('date has changed!');
  }                  
});

不幸的是,change函数从不触发.在日期选择器中更改日期后如何调用函数?

Unfortunately, the change function never fires. How do I call a function when the date is changed in the date picker?

推荐答案

引导程序4

Bootstrap 4不再支持eonasdan datepicker插件,但是有一个新插件: https://tempusdominus.github.io/bootstrap-4

The eonasdan datepicker plugin is no longer supported in Bootstrap 4, but there is a new plugin: https://tempusdominus.github.io/bootstrap-4

"Tempus Dominus是非常流行的Eonasdan/bootstrap-datetimepicker的继承者"

"Tempus Dominus is the successor to the very popular Eonasdan/bootstrap-datetimepicker"

要检测更改事件,请使用:

To detect the change event, use:

$("#datetimepicker1").on("change.datetimepicker", function (e) {
    if (e.oldDate !== e.date) {
        alert('You picked: ' + new Date(e.date).toLocaleDateString('en-US'))
    }
})

日期选择器演示: https://codeply.com/p/kS0t1Ko61K

引导程序3 (原始答案)

根据文档,事件为dp.change:

$('#myDatePicker').datetimepicker().on('dp.change',function(e){
    console.log(e)
})

http://www.codeply.com/go/5cBJkEHiAt

这篇关于Bootstrap DatePicker-Onchange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆