在 jquery ui datepicker 中显示其他月份

发布于 2024-12-27 21:27:25 字数 273 浏览 3 评论 0原文

我需要在我的 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,

enter image description here

Kindly Anyone help..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单身情人 2025-01-03 21:27:25

我找不到任何可以让您控制“其他月份”单元格中显示的文本的东西,但您可以绕过它。

Guganeshan.T 走在正确的轨道上。但棘手的部分是在正确的时间应用更改。 beforeShowonChangeMonthYear 事件在新月份显示之前触发,并且这些事件有after版本。对于这种情况,我通常的技巧是使用 setTimeout 如果超时为零,则可以有效地让您在浏览器再次获得控制权并且当前 JavaScript 块完成运行之后调用一个函数。所以像这样的东西应该可以解决问题:

function ickyHyphenKludge(inst) {
    setTimeout(function() {
        inst.dpDiv.find('.ui-datepicker-other-month span.ui-state-default').html('-');
    }, 0);
}

$("#datepicker").datepicker({
    showOtherMonths: true,
    selectOtherMonths: false,
    beforeShow: function(input, inst) {
        ickyHyphenKludge(inst);
    },
    onChangeMonthYear: function(year, month, inst) {
        ickyHyphenKludge(inst);
    }
});

演示: 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 and onChangeMonthYear 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 use setTimeout 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:

function ickyHyphenKludge(inst) {
    setTimeout(function() {
        inst.dpDiv.find('.ui-datepicker-other-month span.ui-state-default').html('-');
    }, 0);
}

$("#datepicker").datepicker({
    showOtherMonths: true,
    selectOtherMonths: false,
    beforeShow: function(input, inst) {
        ickyHyphenKludge(inst);
    },
    onChangeMonthYear: function(year, month, inst) {
        ickyHyphenKludge(inst);
    }
});

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.

怂人 2025-01-03 21:27:25

我检查了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文