【问题标题】:Full Calendar Add event not via promot不通过提示添加完整日历
【发布时间】:2023-03-15 18:32:01
【问题描述】:

我想知道当用户单击完整日历的黑色部分时,我如何允许用户填写表单而不是似乎弹出的促销框

这基本上是我到目前为止所做的。正如你所看到的,我让它将数据发送到一个正在运行的 PHP 页面,但我对提示框不满意,而是希望它是一个很好的表单,他们也可以添加注释。

select: function(start, end, allDay) {
                    var title = prompt('Event Title:');
                        if (title) {
                            calendar.fullCalendar('renderEvent',
                                {
                                    title: title,
                                    start: start,
                                    end: end,
                                    allDay: allDay,

                                },
                                true // make the event "stick"
                            );
                             year = new Date(start).getFullYear();
                             month = new Date(start).getMonth()+1;
                             month = ((month < 10) ? '0' : '') + month;

                             day = ((new Date(start).getDate() < 10) ? '0' : '') + new Date(start).getDate();

                             hours = ((new Date(start).getHours() < 10) ? '0' : '') + new Date(start).getHours();

                             min = ((new Date(start).getMinutes() < 10) ? '0' : '') + new Date(start).getMinutes();

                             sec = ((new Date(start).getSeconds() < 10) ? '0' : '') + new Date(start).getSeconds();

                            start = year + '-' + month + '-' + day +' '+hours+':'+min+':'+sec;

                            year = new Date(end).getFullYear();
                             month = new Date(end).getMonth()+1;
                             month = ((month < 10) ? '0' : '') + month;

                             day = ((new Date(end).getDate() < 10) ? '0' : '') + new Date(end).getDate();

                             hours = ((new Date(end).getHours() < 10) ? '0' : '') + new Date(end).getHours();

                             min = ((new Date(end).getMinutes() < 10) ? '0' : '') + new Date(end).getMinutes();

                             sec = ((new Date(end).getSeconds() < 10) ? '0' : '') + new Date(end).getSeconds();

                            end = year + '-' + month + '-' + day +' '+hours+':'+min+':'+sec;
                            //alert(start+' - '+end);

                            $.get("system/classes/core.php?task=calendar&q=addnew&userid="+userid+"&title="+title+"&start="+start+"&end="+end+"&allDay="+allDay, function(data) {
                                alert(title + ' was created for '+ start +' '+ end);
                            });
                        }
                            calendar.fullCalendar('unselect');
                },

【问题讨论】:

    标签: jquery forms fullcalendar prompt


    【解决方案1】:

    您需要首先创建一个带有标题的表单以及您想提交的所有其他内容。然后将其包装在一个隐藏的 div 中。像这样......(简单的例子)

    <div class="popup" style="display:none; position:fixed; top:25%; left:25%; background-color:white;">
      <input class"title" type="text" size="26" />
      <a href="#" onclick="return false" class="submitFrom">submit</a>&emsp;
      <a href="#" onclick="return false" class="exit">cancel</a>
    </div>
    

    每次进行选择时,它都会 .show() 隐藏的 div。填写表单,提交该表单的 .click() 提交后,它将发送信息并再次隐藏 div。

    select: function(start, end, allDay){
      $(".popup").show();
      var start = Date.parse(start) / 1000;
      var end = Date.parse(end) / 1000;
      var allDay = allDay;
      var wipit = // create a session id such as a random number that can be cleared later to prevent double submissio
    
      $(".submitForm").click(function(){
      var title = $(".title").val();
    
      if(title){
        $.post("/*page name*/", {title: title, start:start, end:end, allDay:allDay}, function(){
          $(".title").val("")
          title = "";
          wipit = "";
          start = '';
          end = '';
          allDay = '';
          calendar.fullCalendar('unselect');
          calendar.fullCalendar('refetchEvents');
        });
      } else {
        // clear all information, unselect events, and alert that a title needs to be entered
      }
      $(".popup").hide();
      });
    
      $(".exit").click(function(){
        // clear all info, unselect events and...
        $(".popup").hide();
      });
    }
    

    同样,这是非常简单和通用的,必须根据您的规格进行修改,并根据您的喜好设置样式,但它应该可以工作。让我知道这是否有帮助

    【讨论】:

    • 一个小问题是不发送开始和结束时间,或者如果它是一整天的事件
    • 您需要将其添加到 post 请求中,通过 start: start、end: end 和 allDay: allDay。
    • 您还必须解析日期
    • 我还注意到,因为我的日历在一个函数中,而不是在文档就绪部分,它不允许 $(".submitForm").click(function(){});运行
    • 嗯,呃...不要试图粗鲁,但正如我之前所说,这个例子是为了帮助你入门,我没有意识到你需要我解释 jquery 的基础知识或全日历作品。我很清楚事件处理程序在 jquery 中是如何工作的,此外,除非您尝试在事件上激活日历,否则它应该已经在 $(document).ready(); 中。你需要什么???你想让我给你完整的功能代码,这样你就可以简单地复制和粘贴吗?还是你只是在寻求帮助???
    猜你喜欢
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-05
    • 2023-01-20
    • 2017-05-23
    相关资源
    最近更新 更多