twitter-bootstrap Bootstrap DatePicker - Onchange
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43046792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap DatePicker - Onchange
提问by user687554
I am using the Bootstrap 3 Datepickerplugin. 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
我正在使用Bootstrap 3 Datepicker插件。当用户选择日期时,我想更新 UI 的各个部分。我基本上是在尝试创建一个在日期更改时调用的函数。然而,我的尝试并没有成功。目前,我正在尝试以下
$('#myDatePicker').datetimepicker({
change: function() {
alert('date has changed!');
}
});
Unfortunately, the changefunction never fires. How do I call a function when the date is changed in the date picker?
不幸的是,该change函数永远不会触发。在日期选择器中更改日期时如何调用函数?
采纳答案by Zim
Bootstrap 4
引导程序 4
The eonasdan datepicker plugin is no longer supported in Bootstrap 4, but there is a new plugin: https://tempusdominus.github.io/bootstrap-4
Bootstrap 4 不再支持 eonasdan datepicker 插件,但有一个新插件:https://tempusdominus.github.io/bootstrap-4
"Tempus Dominus is the successor to the very popular Eonasdan/bootstrap-datetimepicker"
“Tempus Dominus 是非常流行的 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'))
}
})
Datepicker demo: https://codeply.com/p/kS0t1Ko61K
日期选择器演示:https://codeply.com/p/kS0t1Ko61K
Bootstrap 3(original answer)
Bootstrap 3(原始答案)
According to the docs, the event is dp.change:
根据文档,事件是dp.change:
$('#myDatePicker').datetimepicker().on('dp.change',function(e){
console.log(e)
})
回答by Lahiru
You can try this:
你可以试试这个:
$("#myDatePicker").datetimepicker().on('changeDate', function(e) {
alert('date has changed!');
});
Bootstrap doc reference: changeDate
Bootstrap 文档参考: changeDate
回答by Gizmo3399
For the Bootstrap datepicker the event is changeDate in case people are looking for that: Docs
对于 Bootstrap 日期选择器,事件是 changeDate,以防人们正在寻找:Docs
$("input[name='Date']").datepicker().on('changeDate', function (e) {
console.log(e); //Where e contains date, dates and format
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/js/bootstrap.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.css" rel="stylesheet"/>
<input name="Date"/>
回答by user8220317
OnChange : Function(data)
{
valueAccessor()(data);
}

