jQuery UI datepicker奇怪的问题(在Firefox中发生)

编程入门 行业动态 更新时间:2024-10-14 12:22:47
本文介绍了jQuery UI datepicker奇怪的问题(在Firefox中发生)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用以下功能来禁用日期选择器日历中从2011-02-13到2011-02-18的日期:

I use the following function to disable days from 2011-02-13 to 2011-02-18 in the date picker calendar:

function no_disabled_days(date){ dateStr1 = '2011-02-13'; dateStr2= '2011-02-18'; disabled_start_day = new Date(dateStr1); disabled_end_day = new Date(dateStr2); if(date >= disabled_start_day && date <= disabled_end_day){ return [false]; } return [true]; } $("#reserve_date").datepicker({ beforeShowDay: no_disabled_Days });

例如,如果 dateStr1 ='2011-02-13', dateStr2 ='2011-02-18',则表示 2011-02 -13 至 2011-02-18 已被禁用.

For example, if dateStr1='2011-02-13', dateStr2='2011-02-18', the days from 2011-02-13 to 2011-02-18 are disabled.

自从我使用

if(date >= disabled_start_day && date <= disabled_end_day)(请注意' = '符号)

因此," 2011-02-13 "和" 2011-02-18 "被禁用.

so, '2011-02-13' and '2011-02-18' are disabled.

在 Chrome 浏览器中一切正常,但是,当我在 Firefox 中进行测试时,并未禁用确切的disable_start_date,即" 2011-02 -13 "未禁用,其他日子正常运行.为什么?

Things are working fine in Chrome browswer, however, when I test in Firefox, the exact disable_start_date is not disabled, that's '2011-02-13' is not disabled, other days are working properly. Why?

为什么禁用开始日期( 2011-02-13 )在Firefox中未处于禁用状态?

Why the disabled start date (2011-02-13) is not in disable status in firefox?

推荐答案

您遇到了时区问题.创建日期对象时,本地时区会影响Date对象的时间部分,从而影响比较.解决方案是在创建Date对象时显式设置时间.

You're running into a timezone issue. When you create your date object, your local timezone is affecting the time component of the Date objects, which, in turn, affects the comparison. The solution is to explicitly set the time when you create the Date objects.

此外,在函数中使用变量的方式是创建额外的全局变量.您应该使用var关键字使它们在函数中本地化.

Additionally, the way you are using variables in your function is creating extra global variables. You should use the var keyword to make them local to the function.

这是更正的代码:

function no_disabled_days(date){ var dateStr1 = '2011-02-13T00:00:00'; var dateStr2= '2011-02-19T00:00:00'; var disabled_start_day = new Date(dateStr1); var disabled_end_day = new Date(dateStr2); if(date >= disabled_start_day && date <= disabled_end_day){ return [false]; } return [true]; } $("#reserve_date").datepicker({ beforeShowDay: no_disabled_days });

还有一个可行的示例(已在Firefox和Chrome中测试):

And a working example (tested in Firefox and Chrome):

jsfiddle/ChrisMH/5jX6B/1/

更多推荐

jQuery UI datepicker奇怪的问题(在Firefox中发生)

本文发布于:2023-10-24 20:26:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524924.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:奇怪   发生   UI   jQuery   Firefox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!