繁体   English   中英

关于 php 全日历

[英]about php full calendar

当我点击日历中的一个项目时,它会显示它的特定任务。 一秒钟后,日历将消失。 但我想在不消失的情况下显示任务。 当我添加一个函数根据项目调用日历时,那么这个问题就开始了。

这是jquery中的代码

{
    guyid = "";

    $('.guyid').click(function (){
        this.guyid = $(this).attr('id');
    //  alert('test:'+this.guyid);
            CalenderCall(this.guyid);

    });

    function CalenderCall(guyid){

//alert(guyid);
        $('#calendar').fullCalendar({
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,basicDay'
                },
                editable: true,
                eventLimit: true, // allow "more" link when too many events

                events: [
                    {
                        title: guyid,
                        start: '2016-02-04'
                    },
                    {
                        title: 'Event1',
                        start: '2016-02-04'
                    },

                    {
                        title: 'Event1',
                        start: '2016-02-17'
                    },
                    {
                        title: 'Long Event',
                        start: '2016-02-06',
                        end: '2016-02-10'
                    }

                    // etc...
                    ],
                    color: 'yellow',   // an option!
                    textColor: 'black' // an option!
        });
    }

});

这是身体的一部分

<!-- <div style="width: auto; height: 200px; border: 2px solid black;"></div> -->
<a href="tasks.php"><b>Tasks</b></a><br>
<div style="position: absolute;">
<?php
    $phplink = mysql_connect('localhost:3306', 'root', '');
    if (!$phplink) {
        die("Could not connect:" .mysql_error());
    }
    $db = mysql_select_db('jhoro_pm', $phplink) or die("Could not connect to db:" .mysql_error());
    $result_guy = mysql_query("SELECT id, name, can_login FROM person WHERE can_login=1");
    while ($row_guy=mysql_fetch_array($result_guy)) {
        //echo '<input type="hidden" class="guyid" value="' .$row_guy[0]. '" />';
        echo '<a href="index.php" class="guyid" id="' .$row_guy[0]. '">' .$row_guy[1]. '</a><br>';
    }
?>

这是没有日历的项目。 当单击其中任何一个时,任务将与日历一起显示。 但一秒钟后日历消失

在此处输入图片说明

好的,那么您必须执行以下操作

首先,使用以下代码更改您的代码。

<!-- <div style="width: auto; height: 200px; border: 2px solid black;"></div> -->
<a href="tasks.php"><b>Tasks</b></a><br>
<div style="position: absolute;">
<?php
    $phplink = mysql_connect('localhost:3306', 'root', '');
    if (!$phplink) {
        die("Could not connect:" .mysql_error());
    }
    $db = mysql_select_db('jhoro_pm', $phplink) or die("Could not connect to db:" .mysql_error());
    $result_guy = mysql_query("SELECT id, name, can_login FROM person WHERE can_login=1");
    while ($row_guy=mysql_fetch_array($result_guy)) {
        echo '<a href="javascript:void(0);" class="guyid" id="' .$row_guy[0]. '">' .$row_guy[1]. '</a><br>';

    }

        echo '<input type="hidden" id="selectedPerson" class="guyid" value="' .$row_guy[0]. '" />';
?>
  1. 从您的锚标记中删除 href="index.php"。 (href 会调用每次点击,这就是您的日历消失的原因。
  2. 为所选人员设置隐藏字段。 (外侧while循环)。

现在,对您的 jQuery 代码进行一些微调。

{
    guyid = "";

    $('.guyid').click(function (){
        this.guyid = $(this).attr('id');
        $('#selectedPerson').val(this.guyid);
        $('#calendar').fullCalendar('rerenderEvents');
    });

        $('#calendar').fullCalendar({
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,basicDay'
                },
                editable: true,
                eventLimit: true, // allow "more" link when too many events

                events: [
                    {

                        title: 1,
                        start: '2016-02-04'
                    },
                    {
                        title: 2,
                        start: '2016-02-04'
                    },

                    {
                        title: 3,
                        start: '2016-02-17'
                    },
                    {
                        title: 4,
                        start: '2016-02-06',
                        end: '2016-02-10'
                    }

                    ],
                    eventRender: function(event, element) {
                       return (($('#selectedPerson').val()) == event.title);
                   },
                    color: 'yellow',   // an option!
                    textColor: 'black' // an option!
        });
});

这肯定会奏效。 如果您仍然卡在任何地方,请添加评论。

保持现有代码(您在问题中提到的)原样。

只需添加如下简单的 ajax url 即可加载个人任务。

events: "urltofetchpersonwisetasks/?guyid="+guyid,

并且服务器以 Guyid 作为请求参数获取此请求,并进行数据库调用以获取人员的任务并发送 json 响应。 像 json_encode(person_task_array)。 这将自动加载所选人员的任务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM