全日历选择整个星期 [英] Select entire week in fullcalendar

查看:154
本文介绍了全日历选择整个星期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用fullcalendar插件时遇到了麻烦,即我试图仅单击一下就试图在月视图中选择整个星期,然后创建一个这样的事件.换句话说,如果您单击特定星期中的任何一天,则该周将突出显示并创建一个事件.此后,该事件应输入到我的数据库中.

im having trouble with the fullcalendar plugin where im trying to make an entire week selected in month view with just on click and then create an event of this. In other words, if you click any day on a specific week, that week will be highlighted and an event will be created. Thereafter this event should be entered into my database.

这是我到目前为止所拥有的:

This is what I have so far:

<script>
    $(document).ready(function() {
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
// page is now ready, initialize the calendar...

$("#calendar").fullCalendar({
    // put your options and callbacks here
    header: {
            right: "today prev,next",
            left: "title",
        },
    height:650,
        selectable: true,
        selectHelper: true,
        select: function(start, end, allDay) {
            var title = confirm("Apply for kitchenweek?");
            if (title) {
                calendar.fullCalendar("renderEvent",
                    {
                        title: title,
                        start: start,
                        end: end,
                        allDay: allDay
                    },
                    true // make the event "stick"
                );
            }
            calendar.fullCalendar("unselect");
        },
    editable: true,
    events: "/json-events.php"
   })
  });
</script>

任何帮助将不胜感激.

推荐答案

一些用户没有注意到OP编辑了他们的问题以包括答案,因此为了便于访问,我将其重新发布为答案,以便人们不要不要错过. 完全公开这不是我的代码,这是OP的代码,请用他的问题代替这个答案. 在这里说的是代码:

A few users didn’t notice that OP edited their question to include an answer, so for ease of access I’m reposting it as an answer so people don’t miss it. Full disclosure this is not my code, it is OP’s code, upvote his question instead of this answer. that being said here is the code:

(由于我没有写,所以我不能保证它能正常工作,也不能解释它)

(Also as I did not write it I cannot vouch for it working,nor can I explain it)

   <script>
        $(document).ready(function() {
        var date = new Date();
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();
    // page is now ready, initialize the calendar...

   var calendar = $("#calendar").fullCalendar({
    // put your options and callbacks here
    header: {
            right: "today prev,next",
            left: "title"
        },
    height:650,
    events: "/json-events.php",
    //selectable: true,
        selectHelper: true,
    dayClick: function(start, allDay, jsEvent, view) {
        $(this).parent().siblings().removeClass("week-highlight");
        $(this).parent().addClass("week-highlight");
        if(start < date && start.getDate() != date.getDate())
        {
            alert("Cannot select past dates.");
            $(this).parent().removeClass("week-highlight");
            return;
        }
            var title = confirm("Apply for kitchenweek?");
             var now = date? new Date(start-1) : new Date();
             now.setHours(0,0,0,0);
             var monday = new Date(now);
             monday.setDate(monday.getDate() - monday.getDay() + 1);
             var sunday = new Date(now);
             sunday.setDate(sunday.getDate() - sunday.getDay() + 7);
            if (title) {
                calendar.fullCalendar("renderEvent",
                    {
                        title: "Kitchenweek for: '; echo $username; echo'",
                        start: monday,
                        end: sunday,
                        allDay: allDay
                    },
                    true // make the event "stick"
                );
            var mondaydate = $.fullCalendar.formatDate(monday,"yyyy-MM-dd");
            var sundaydate = $.fullCalendar.formatDate(sunday,"yyyy-MM-dd");
            var pname = "Kitchenweek for: '; echo $username; echo'";
            var username = "'; echo $username; echo'";
            $.ajax({
            type: "POST",
            url: "/new_event.php",
            data: {
            startdate: mondaydate,
            enddate: sundaydate,
            event_title: pname,
            uname: username
            }
            });
            }
            $(this).parent().removeClass("week-highlight");
        }
});
});
</script>

这篇关于全日历选择整个星期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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