Javascript 选择事件上的 Bootstrap Datetimepicker
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36127937/
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 Datetimepicker on select event
提问by Zelenka
How do I access a js function exampleFunction() when date is selected?I want to pass the date value there.
选择日期时如何访问 js 函数 exampleFunction()?我想在那里传递日期值。
text_field_tag for datetimepicker (haml):
datetimepicker (haml) 的 text_field_tag:
= text_field_tag 'start_day', class: 'datepick'
Javascript:
Javascript:
$(".datepick").datetimepicker({
timepicker: false,
format: 'd/m/Y',
closeOnDateSelect: true
});
采纳答案by M. Junaid Salaat
If this is the plugin you are using then it would be Like this.
如果这是您正在使用的插件,那么它将是这样的。
$(".datepick").datetimepicker({
onChangeDateTime:exampleFunction
});
function exampleFunction(){
console.log("Date Selected")
}
For full option list Reference: http://xdsoft.net/jqplugins/datetimepicker/
完整选项列表参考:http: //xdsoft.net/jqplugins/datetimepicker/
Hope it helps.
希望能帮助到你。
回答by Akshay Jindal
You can achieve this by using below given code:
您可以使用以下给定的代码来实现这一点:
$("#datetimepicker6").on("dp.change", function (e) {
console.log(e.date);
});
I your case, it should be :
我你的情况,应该是:
$(".datepick").on("dp.change",function(e){ exampleFunction(e.date) });
Remember this will call the example function on change in value of each datetimepicker, since you used class.
请记住,这将在每个 datetimepicker 的值发生变化时调用示例函数,因为您使用了 class。
Reference URL: https://eonasdan.github.io/bootstrap-datetimepicker/
回答by ShirleyCC
Simply:
简单地:
$(".datepick").datetimepicker({
format: 'd/m/Y',
}).on('select', function (e) {
console.log('on select event');
});
回答by Shivani P
Try this :
尝试这个 :
$(".datepick").datetimepicker({
timepicker: false,
format: 'd/m/Y',
closeOnDateSelect: true
}).on('dp.change', function (ev) {
exampleFunction() ;//your function call
});