jQuery UI DatePicker 更改突出显示“今天"日期 [英] jQuery UI DatePicker change highlighted "today" date

查看:28
本文介绍了jQuery UI DatePicker 更改突出显示“今天"日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 jQuery Datepicker 中显式更改突出显示的今天的日期.我试过设置默认日期,但突出显示的日期仍然是我本地计算机的日期,即今天.

I would like to explicitly change the highlighted today's date in jQuery Datepicker. I've tried setting the default date but still the highlighted date is my local computer's date which is today.

我想这样做是因为我使用的是自定义时区.基本上,此自定义时区中的当前年/月/日与我本地计算机的当前日期不同.

I would like to do this because I am using a custom timezone. Basically the current year/month/date in this custom timezone is different than my local computer's current date.

例如

假设今天的日期是 07/10/2014 与我电脑的日期相同,但是使用自定义时区,突出显示的今天的日期应该是 07/09/2014:

Say today's date is 07/10/2014 same with my computer's date, but using a custom timezone, the today's date highlighted should be 07/09/2014:

推荐答案

不幸的是,'Today' 是在 DatePicker 的 HTMLRendering 阶段计算的,这意味着为了覆盖"你需要重新定义 _generateHTML$.datepicker 方法.我还发现默认状态下的今天"按钮会被此覆盖破坏,因此也有必要覆盖该方法.

Unfortunately, 'Today' is calculated at the HTMLRendering stage of the DatePicker, this means that in order to 'override' you need to redefine the _generateHTML method of $.datepicker. Ive also found that the 'Today' button in it's default state gets broken by this override, so it is necessary to override that method too.

基本上日期选择器设置一个像这样的内部变量tempDate = new Date()",然后使用它来创建今天".我们所做的只是用一些时区偏移代码覆盖该变量,其余的自行解决.

Basically the datepicker sets an internal variable like this 'tempDate = new Date()' and then uses that to create 'today'. All we do is override that variable with some timezone offsetting code, and the rest sorts itself out.

在下面的演示中,顶部是 appLocalTimezone 的变量,将其设置为您想要的时区,它将根据应用程序更新日期选择器.原始代码/答案的所有功劳都在小提琴中

In the below demo, at the top is a variable for appLocalTimezone, set this to your desired timezone and it will updated the datepicker based on the app. All credit for original code/answers are in the fiddle

jsFiddle 演示

这篇关于jQuery UI DatePicker 更改突出显示“今天"日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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