在 jquery ui datepicker 中显示其他月份
我需要在我的 jquery ui 日期选择器中将其他月份显示为“-”。
$( "#datepicker" ).datepicker({
showOtherMonths: true
});
上面的代码显示了其他月份的日期。但是,我需要将其他月份日期显示为“-”。
例如,
请任何人帮忙..
I need to show other months as '-' in my jquery ui datepicker.
$( "#datepicker" ).datepicker({
showOtherMonths: true
});
The above code shows the other month dates. But, I need to show other months date as '-'.
For Ex,
Kindly Anyone help..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找不到任何可以让您控制“其他月份”单元格中显示的文本的东西,但您可以绕过它。
Guganeshan.T 走在正确的轨道上。但棘手的部分是在正确的时间应用更改。
beforeShow
和onChangeMonthYear
事件在新月份显示之前触发,并且这些事件有after版本。对于这种情况,我通常的技巧是使用setTimeout
如果超时为零,则可以有效地让您在浏览器再次获得控制权并且当前 JavaScript 块完成运行之后调用一个函数。所以像这样的东西应该可以解决问题:演示: http://jsfiddle.net/ambigously/YKNmV/1 /
这很糟糕,而且很臭,但它有效,它应该很坚固,我想不出任何其他方法。
I can't find anything that allows you to control the text that is displayed in the "other month" cells but you can kludge your way around it.
Guganeshan.T is on the right track. But the tricky part is applying the change at the right time. The
beforeShow
andonChangeMonthYear
events are fired before the new month is displayed and there are after versions of those events. My usual trick for situations like this is to usesetTimeout
with a timeout of zero, that effectively lets you queue up a function to be called once the browser gets control again and that's after the current chunk of JavaScript has finished running. So something like this should do the trick:Demo: http://jsfiddle.net/ambiguous/YKNmV/1/
That's pretty kludgey and smelly but it works, it should be pretty solid, and I can't think of any other way.
我检查了 jQuery UI 的 DatePicker 控件中使用的 CSS。他们使用
ui-priority-secondary
类来表示其他月份的日期。因此,您可以做的是,使用 jQuery 来定位使用该特定类的元素,并将 HTML 替换为
-
并将其居中。我尝试了以下方法并且成功了。
$('.ui-datepicker-calendar .ui-priority-secondary').html('-').css('text-align', 'center')
希望有帮助
更新:
由于我仅使用
Firebug
控制台进行了检查,因此没有看到无法在正确的时间应用它的场景。 @mu 太短 已经指出了这一点并且已经一个可行的解决方案。I checked the CSS used in the jQuery UI's DatePicker control. They use the class
ui-priority-secondary
for dates in other months.So what you can do is, use jQuery to locate elements that use that particular class and replace the HTML to
-
and center it.I tried the following and it worked.
$('.ui-datepicker-calendar .ui-priority-secondary').html('-').css('text-align', 'center')
Hope that helps
UPDATE:
Since I checked it only with the
Firebug
console, didn't see the scenario where it won't be applied at the right time. @mu is too short has pointed that out and has a working solution.