自定义Jquery UI Datepicker [英] Customize Jquery UI Datepicker

查看:88
本文介绍了自定义Jquery UI Datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最有可能怀疑是不可能的,但我想知道如果有人曾在定制JQuery UI日期选择器上显示的日历以改变日期的情况下工作。
这是我的情况:我的公司使用的是一个会计年度而不是日历年,并且每年的开始日期不同,实际上我在此期间创建了Excel日历,并且我可以在JavaScript上使用原则,我的问题是,是否有办法在日历上设置一个初始日期,并从那一天开始计算周数......



示例



财政年度从8月28日开始(星期日),因为:
AUG28-SEPT3 = FW1

SEPT4-SEPT10 = FW2

SEPT11-SEPT17 = FW3







等等...
i想要显示一个从2011年8月28日(fw1)开始到2012年8月25日(fw52)开始的周历。找到任何相关的东西,如果我不够清楚,请让我知道,所以我可以重新表述。 本周计算,请参阅 jQuery UI calculateWeek 。它是一个开始,但对那些文档不太有帮助。更有用的是这里博客文章



无论如何,这里是我设法破解的代码,请参阅下面的链接以查看它的工作原理。



  • 定义datapicker:

      $(# (
    calculateWeek:fisc,
    maxDate:'08 / 25/12',
    minDate:'08 / 28/11',
    showWeek:true
    });

  • 以及计算星期的函数:

      function fisc(date){
    var checkDate = new Date(date.getTime());
    checkDate.setDate(checkDate.getDate()+ 4 - (checkDate.getDay()|| 7));
    var time = checkDate.getTime();
    checkDate.setMonth(7);
    checkDate.setDate(28);
    var week =(Math.floor(Math.round((time-checkDate)/ 86400000)/ 7)+ 2);
    if(week <1){
    week = 52 + week;
    }
    返回'FW:'+ week;
    }

    >点击此处查看此功能



    我相信这可能不是完成此操作的完美方式,但它似乎起作用对于这个夜晚的这段时间,希望它能指引你正确的方向。


    I most likely suspect is not possible but I wanted to know If someone was has worked with customizing the calendar displayed on Jquery UI datepicker to the extend of changing the dates. Here is my situation: My company uses a fiscal year instead of a calendar year where and it begins on a different day each year, I actually made an excel calendar in the mean time and I could use the principle on javascript, my question is if there is a way to set up an initial date on the calendar and start counting weeks from that day...

    Example

    Fiscal year starts on August 28 (sunday), given that : AUG28-SEPT3 = FW1
    SEPT4-SEPT10 = FW2
    SEPT11-SEPT17 = FW3
    .
    .
    .
    and so on ... i want to show a calendar with the week number starting on AUG28 2011 (fw1) and ending on aug25 2012 (fw52).

    i already read the documentation and I cant' find anything related, if I was not clear enough please let me know so I can rephrase.

    解决方案

    You will have to create your own week calculation, see the docs for jQuery UI calculateWeek. Its a start, but not too helpful in those doc's. A little more useful was this blog post here.

    Anyway here is the code I have managed to hack together, see the link below to see it working.

  • Define the datapicker:

    $("#mydatepicker").datepicker({
        calculateWeek: fisc,
        maxDate: '08/25/12',
        minDate: '08/28/11',
        showWeek: true
    });
    

  • And the function to calculate the weeks:

    function fisc(date) {
        var checkDate = new Date(date.getTime());
        checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
        var time = checkDate.getTime();
        checkDate.setMonth(7); 
        checkDate.setDate(28);
        var week = (Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 2);
        if (week < 1) {
            week = 52 + week;
        }
        return 'FW: '+week;
    }
    

    Click here to see this in action

    I'm sure this probably isn't the perfect way to do this, but it seems to work for this time of night, hopefully it will point you in the correct direction.

    这篇关于自定义Jquery UI Datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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