【问题标题】:jquery ui date picker limit to Sundaysjquery ui日期选择器限制为星期日
【发布时间】:2011-05-27 16:08:04
【问题描述】:

我在这里查看了此类问题的一些答案,但无法让它们按照我的需要工作。我需要让我的 jQuery UI 日期选择器只允许选择过去的星期日。这可以吗?

谢谢

【问题讨论】:

    标签: javascript jquery jquery-ui jquery-ui-datepicker


    【解决方案1】:
    // Enable Sunday only
    $("#datepickerID").datepicker({
        dateFormat: 'dd-mm-yy',
        minDate: 1,
        beforeShowDay: enableSUNDAYS
    });
    // Custom function to enable SUNDAY only in jquery calender
    function enableSUNDAYS(date) {
        var day = date.getDay();
        return [(day == 0), ''];
    }
    

    【讨论】:

    • 嗨,这个方法对我不起作用,我收到以下错误:p.apply is not a function [Break On This Error] A);t=(this._getFirstDayOfMonth(m,g )-h+...()==N.getTime()&&g==a.selectedMonth&& 在 jquery-ui 文件的第 531 行有帮助吗?
    【解决方案2】:

    It's not exactly your situation, but contains what you need to know to do what you need to do:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
        <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css"
            type="text/css" media="all" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"
            type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
    
                // 0 = monday, 1 = tuesday, 2 = wednesday, 3 = thursday,
                // 4 = friday, 5 = saturday, 6 = sunday
    
                var daysToDisable = [2, 4, 5];
    
                $('#<%= txtDate.ClientID %>').datepicker({
                    beforeShowDay: disableSpecificWeekDays
                });
    
                function disableSpecificWeekDays(date) {
                    var day = date.getDay();
                    for (i = 0; i < daysToDisable.length; i++) {
                        if ($.inArray(day, daysToDisable) != -1) {
                            return [false];
                        }
                    }
                    return [true];
                }
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
        </form>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2012-05-05
      • 1970-01-01
      • 1970-01-01
      • 2012-09-09
      • 2011-04-19
      • 1970-01-01
      • 2018-01-21
      • 1970-01-01
      相关资源
      最近更新 更多