最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Sunday only on Jquery Datepicker? - Stack Overflow

programmeradmin0浏览0评论

AIM: TO only allow users to select sunday on the datpicker calendar.

Currently I have it almost done, except for some reason every other day except Sunday works. When I use 7 for Sunday in the code below the entire calendar is unclickable, any other day works perfect.

$(document).ready(function() {

    $("#datepicker2").datepicker({ 
        autoSize: true,         // automatically resize the input field 
        altFormat: 'yy-mm-dd',  // Date Format used
        firstDay: 1, // Start with Monday
        beforeShowDay: function(date)

        { return [date.getDay() == 7,''];}}); // Allow only one day a week
});

Question: How can I only allow Sunday selection?

AIM: TO only allow users to select sunday on the datpicker calendar.

Currently I have it almost done, except for some reason every other day except Sunday works. When I use 7 for Sunday in the code below the entire calendar is unclickable, any other day works perfect.

$(document).ready(function() {

    $("#datepicker2").datepicker({ 
        autoSize: true,         // automatically resize the input field 
        altFormat: 'yy-mm-dd',  // Date Format used
        firstDay: 1, // Start with Monday
        beforeShowDay: function(date)

        { return [date.getDay() == 7,''];}}); // Allow only one day a week
});

Question: How can I only allow Sunday selection?

Share Improve this question asked Feb 15, 2013 at 17:56 RhysRhys 2,8779 gold badges48 silver badges70 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Date.getDay() returns a value in the range 0-6, not 1-7.

beforeShowDay: function(date) {
    return [date.getDay() === 0,''];
}
发布评论

评论列表(0)

  1. 暂无评论