繁体   English   中英

使用javascript和php显示日历

[英]to display calendar using javascript and php

我是该PHP的新手,我试图开发一个代码,以便当我单击启动日历时它会显示日历,当我选择它将在文本字段中显示的日期时,我的问题是当我单击启动日历时它不显示feburay月份。 。我不知道我代码中的错误,任何人都可以在这方面帮助我..在此先感谢..这是我开发的代码...

<?php

$day = $_GET["day"];
$month = $_GET["month"];
$year = $_GET["year"];
$sel = $_GET["sel"];
$what = $_GET["what"];
$field = $_GET["field"];
$form = $_GET["form"];

if($day == "") $day = date("j");

if($month == "") $month = date("m");

if($year == "") $year = date("Y");

$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
?>


<html>
<head>
<title>MyCalendar</title>
<link rel="stylesheet" type="text/css" href="calendar.css">
<script language="javascript">
    function goLastMonth(month,year,form,field)
    {

        if(month == 1)
    {
    --year;
    month = 13;
    }       
        document.location.href = 'calendar.php?month='+(month-1)+'&year='+year+'&form='+form+'&field='+field;
    }

    function goNextMonth(month,year,form,field)
    {

        if(month == 12)
    {
    ++year;
    month = 0;
    }   
        document.location.href = 'calendar.php?month='+(month+1)+'&year='+year+'&form='+form+'&field='+field;
    }

    function sendToForm(val,field,form)
    {

        eval("opener.document." + form + "." + field + ".value='" + val + "'");
        window.close();
    }
</script>
</head>
<body style="margin:0px 0px 0px 0px" class="body">
<table width='175' border='0' cellspacing='0' cellpadding='0' class="body">
    <tr>
        <td width='25' colspan='1'>
        <input type='button' class='button' value=' < ' onClick='<?php echo "goLastMonth($month,$year,\"$form\",\"$field\")"; ?>'>
        </td>
        <td width='125' align="center" colspan='5'>
        <span class='title'><?php echo $monthName . " " . $year; ?></span><br>
        </td>
        <td width='25' colspan='1' align='right'>
        <input type='button' class='button' value=' > ' onClick='<?php echo "goNextMonth($month,$year,\"$form\",\"$field\")"; ?>'>
        </td>
    </tr>
    <tr>
        <td class='head' align="center" width='25'>S</td>
        <td class='head' align="center" width='25'>M</td>
        <td class='head' align="center" width='25'>T</td>
        <td class='head' align="center" width='25'>W</td>
        <td class='head' align="center" width='25'>T</td>
        <td class='head' align="center" width='25'>F</td>
        <td class='head' align="center" width='25'>S</td>
    </tr>
    <tr>
<?php
    for($i = 1; $i < $numDays+1; $i++, $counter++)
    {
        $timeStamp = strtotime("$year-$month-$i");
        if($i == 1)
        {

        $firstDay = date("w", $timeStamp);

        for($j = 0; $j < $firstDay; $j++, $counter++)
        echo "<td> </td>";
        }

        if($counter % 7 == 0)
        echo "</tr><tr>";

        if(date("w", $timeStamp) == 0)

        $class = "class='weekend'";
        else
        if($i == date("d") && $month == date("m") && $year == date("Y"))
        $class = "class='today'";
        else
        $class = "class='normal'";

        echo "<td class='tr' bgcolor='#ffffff' align='center' width='25'><a class='buttonbar' href='#' onclick=\"sendToForm('".sprintf("%02d/%02d/%04d", $month, $i, $year)."','$field','$form');\"><font $class>$i</font></a></td>";
    }
?>
    </tr>
</table>
</body>
</html>

这不是您的脚本的修复程序,但可能是您的问题的修复程序。 仅使用预制的完整javascript日历库难道不是很容易吗?

喜欢: Jscalendar 演示

Jquery Ui Datepicker +演示

由于日历将在客户端上运行,因此只能使用客户端代码来完成此任务。 @ RJD22指出,使用javascript和像Jquery这样的预制库。 我认为一般来说,当您可以在客户端端完成使用服务器端的任务时,这会更好,因为服务器资源有限

暂无
暂无

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

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