jquery datepicker选择今天

发布于 2024-11-30 09:39:07 字数 641 浏览 0 评论 0原文

“我使用带有 onSelect 回调函数的内联 JQuery UI 日期选择器。此函数将多个日期的选定日期收集到数组中。我的问题是,日期选择器在启动时调用此函数并选择今天,并将其添加到我的数组中。我怎样才能禁用此行为?我不需要知道今天是哪一天,不想将其自动添加到我的数组中...
预先感谢您的帮助!

编辑:这是我的(非常简单)onSelect 回调按要求:

var blocked_days = new Array([..]);
function updateSelected(dateText)
{
    var toAdd = true;
    for (var i in blocked_days)
    {
        if (dateText == blocked_days[i])
        {
            blocked_days[i] = null;
            toAdd = false;
        }
    }
    if (toAdd === true)
        blocked_days[blocked_days.length] = dateText;

    $("#special_offer_blocked_form_blockeddays").val(blocked_days.join());
}

"im using an inline JQuery UI datepicker with an onSelect callback function. This function collects selected dates in an array for multiple dates. My problem is that datepicker calls this function on startup with selecting today, and adding it to my array. How can I disable this behaviour? I dont need to know which day is today, don't want to add it to my array automatically...
Thanks in advance for nay help!

Edit: Here's my (pretty simple) onSelect callback as requested:

var blocked_days = new Array([..]);
function updateSelected(dateText)
{
    var toAdd = true;
    for (var i in blocked_days)
    {
        if (dateText == blocked_days[i])
        {
            blocked_days[i] = null;
            toAdd = false;
        }
    }
    if (toAdd === true)
        blocked_days[blocked_days.length] = dateText;

    $("#special_offer_blocked_form_blockeddays").val(blocked_days.join());
}

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

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

发布评论

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

评论(1

晨曦慕雪 2024-12-07 09:39:07

你有 onSelect 回调函数的代码吗?

解决这个问题的一种方法是通过检查来更新回调函数,以检查日期是否不是今天。如果不是,则添加日期。

如果您可以提供 onSelect 代码的示例,我将非常乐意查看并添加此代码?

更新:

然后您可以做的是每次调用该函数时设置一个简单的计数器,始终忽略第一次调用。

var number_of_updates = 0;
var blocked_days = new Array([..]);
function updateSelected(dateText)
{
    number_of_updates++;
    if (number_of_updates > 1)
    {
        var toAdd = true;
        for (var i in blocked_days)
        {
            if (dateText == blocked_days[i])
            {
                blocked_days[i] = null;
                toAdd = false;
            }
        }
        if (toAdd === true)
            blocked_days[blocked_days.length] = dateText;
        $("#special_offer_blocked_form_blockeddays").val(blocked_days.join());
    }
}

尝试一下,看看是否有效?

Have you got your code for the onSelect callback function?

One way around it would be to update the callback function with a check that checks that the date is not today. If it isn't then add the date.

If you can provide an example of your onSelect code I will be more than happy to take a look and add this?

Update:

What you could do then is set a simple counter each time the function is called, always ignoring the first call.

var number_of_updates = 0;
var blocked_days = new Array([..]);
function updateSelected(dateText)
{
    number_of_updates++;
    if (number_of_updates > 1)
    {
        var toAdd = true;
        for (var i in blocked_days)
        {
            if (dateText == blocked_days[i])
            {
                blocked_days[i] = null;
                toAdd = false;
            }
        }
        if (toAdd === true)
            blocked_days[blocked_days.length] = dateText;
        $("#special_offer_blocked_form_blockeddays").val(blocked_days.join());
    }
}

Try that and see if that works?

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