添加“今天”事件侦听器jquery-ui datapicker 中的按钮
我正在使用日期选择器形式 jQuery-ui-1.8.16。
我有以下代码:
Site.Calendar = function() {
// Set default setting for all calendars
jQuery.datepicker.setDefaults({
showOn : 'both',
buttonImageOnly : true,
buttonText: '',
changeMonth : true,
changeYear : true,
showOtherMonths : true,
selectOtherMonths : true,
showButtonPanel : true,
dateFormat : "D, d M, yy",
showAnim : "slideDown",
onSelect: Site.Calendar.customiseTodayButton
});
};
Site.Calendar.customiseTodayButton = function(dateText, inst) {
console.log("hello");
};
只有当我选择实际日期而不是“今天”按钮时,才会触发我的 customiseTodayButton 函数。
有什么方法可以覆盖 jQuery 日期选择器中“今天”按钮的工作方式吗?
谢谢
I'm using the datepicker form jQuery-ui-1.8.16.
I have the following code:
Site.Calendar = function() {
// Set default setting for all calendars
jQuery.datepicker.setDefaults({
showOn : 'both',
buttonImageOnly : true,
buttonText: '',
changeMonth : true,
changeYear : true,
showOtherMonths : true,
selectOtherMonths : true,
showButtonPanel : true,
dateFormat : "D, d M, yy",
showAnim : "slideDown",
onSelect: Site.Calendar.customiseTodayButton
});
};
Site.Calendar.customiseTodayButton = function(dateText, inst) {
console.log("hello");
};
My customiseTodayButton function is only getting triggered when I select an actual date and NOT on the Today button.
Is there any way to override how the today button work's in the jQuery datepicker?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现这里发布了以下内容:
jQuery Datepicker 中的“今天”按钮不起作用
它只是重写了 goToToday方法并添加两行新行:
也许有一种更干净的方法可以用您原来的答案马克来解决这个问题?
I found the following posted here:
Today button in jQuery Datepicker doesn't work
It simply rewrites the goToToday method and adds two new lines:
Maybe there is a cleaner way to fix this with your original answer Mark?
单击“今天”按钮时没有标准事件。但是,查看 jquery.ui.datepicker.js 代码,它似乎调用
$.datepicker._gotoToday
。我假设您正在尝试通过customizeTodayButton
更改其当前的行为(不是外观,外观将通过样式来完成)。要改变现有的行为,最好知道它现在做什么。因此,请记住,这是所使用函数的当前代码:要使用您自己的功能覆盖此函数,您需要将代码更新为如下所示:
此外,这是一个有效的 jsFiddle 您正在寻找的内容。
There isn't a standard event for when the today button is clicked. However, taking a look at the jquery.ui.datepicker.js code, it appears that it calls
$.datepicker._gotoToday
. I'll assume bycustomizeTodayButton
you're attempting to change the behavior of what it does currently (not the looks, the looks would be done with styling). To change the existing behavior, it's good to know what it does now. So, that in mind, this is the current code of the function used:To override this function with your own functionality, you'll want to do update your code to something like this:
Also, here's a working jsFiddle of what you're looking for.
我以这种方式实现了 today 按钮的重写:
这非常简单,并且执行了我想要的“选择日期并关闭日期选择器”功能。
I realized the overriding of the today button in this way:
This is quite simple and does the "select date and close datepicker" functionality that I would.