使用 jQuery UI 日期选择器选择日期时的触发功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11610797/
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
Trigger function when date is selected with jQuery UI datepicker
提问by inkwai
How can I trigger onSelect event when I select a selected date on jQuery UI datepicker?
当我在 jQuery UI datepicker 上选择一个选定的日期时,如何触发 onSelect 事件?
回答by Tats_innit
Working demo: http://jsfiddle.net/YbLnj/
工作演示:http: //jsfiddle.net/YbLnj/
Documentation: http://jqueryui.com/demos/datepicker/
文档:http: //jqueryui.com/demos/datepicker/
code
代码
$("#dt").datepicker({
onSelect: function(dateText, inst) {
var date = $(this).val();
var time = $('#time').val();
alert('on select triggered');
$("#start").val(date + time.toString(' HH:mm').toString());
}
});
回答by RTB
Use the following code:
使用以下代码:
$(document).ready(function() {
$('.date-pick').datepicker( {
onSelect: function(date) {
alert(date)
},
selectWeek: true,
inline: true,
startDate: '01/01/2000',
firstDay: 1,
});
});
You can adjust the parameters yourself :-)
您可以自己调整参数:-)
回答by Ando
If you are also interested in the case where the user closes the date selection dialog without selecting a date (in my case choosing no date also has meaning) you can bind to the onClose
event:
如果您也对用户关闭日期选择对话框而不选择日期(在我的情况下选择不选择日期也有含义)的情况感兴趣,您可以绑定到onClose
事件:
$('#datePickerElement').datepicker({
onClose: function (dateText, inst) {
//you will get here once the user is done "choosing" - in the dateText you will have
//the new date or "" if no date has been selected
});
回答by Serdar KU?
$(".datepicker").datepicker().on("changeDate", function(e) {
console.log("Date changed: ", e.date);
});
回答by Franky
If the datepicker is in a row of a grid, try something like
如果日期选择器在网格的一行中,请尝试类似
editoptions : {
dataInit : function (e) {
$(e).datepicker({
onSelect : function (ev) {
// here your code
}
});
}
}