【问题标题】:Set start day of the week in jQuery UI Datepicker?在 jQuery UI Datepicker 中设置一周的开始日期?
【发布时间】:2010-11-21 17:58:45
【问题描述】:

我正在查看 jQuery UI Datepicker (http://jqueryui.com/demos/datepicker/) 的文档,但我找不到如何将一周的第一天设置为星期一。

应用区域设置会将星期一设置为一周的第一天,但​​这也会更改语言。

【问题讨论】:

    标签: jquery jquery-ui


    【解决方案1】:

    这是我使用的示例配置。用“firstDay: 1”查看最后一行。 我认为使用这样的语法来指定日期选择器选项看起来更好;)

    $('#datepickerfield').datepicker({
        constrainInput: true,   // prevent letters in the input field
        minDate: new Date(),    // prevent selection of date older than today
        showOn: 'button',       // Show a button next to the text-field
        autoSize: true,         // automatically resize the input field 
        altFormat: 'yy-mm-dd',  // Date Format used
        beforeShowDay: $.datepicker.noWeekends,     // Disable selection of weekends
        firstDay: 1 // Start with Monday
    })
    

    【讨论】:

      【解决方案2】:

      尝试 firstDay 选项(在选项选项卡中):

      //getter
      var firstDay = $('.selector').datepicker('option', 'firstDay');
      //setter
      $('.selector').datepicker('option', 'firstDay', 1);
      

      【讨论】:

        【解决方案3】:

        将第一天用作星期一:

        $(function() {
            $( "#date_id" ).datepicker({ firstDay: 1 });
        });
        

        【讨论】:

          【解决方案4】:

          您还可以通过为您的语言创建自己的本地化文件以及您自己的设置来实现这一点。详情见本页:http://docs.jquery.com/UI/Datepicker/Localization

          【讨论】:

            【解决方案5】:
                function getFirstDateOfThisWeek(d)
                {
                    var TempDate = new Date(d || new Date());            
                    TempDate.setDate(TempDate.getDate() + (@Config.WeekStartOn - 1 - TempDate.getDay() - 7) % 7);           
                    return TempDate;
            
                }
            
                var StartDate = getFirstDateOfThisWeek(new Date()); //1st date of this week
            

            【讨论】:

              猜你喜欢
              • 2011-06-27
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2019-11-24
              • 1970-01-01
              • 2013-05-29
              • 1970-01-01
              相关资源
              最近更新 更多