由于处理来自数据库的数据,我制作了自己的javascript 日历。我想为我的用户提供选项,以便他/她可以使用下一个和上一个按钮查看任何月份。此日历有效,但我的上一个和下一个按钮不起作用。我的代码是::
我的 php 文件::
我的文件.php
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../_javaScript/jquery-1.9.1.js" type="text/javascript"> </script>
<!-- call calender.js file -->
<script src="../_javaScript/calender.js" type="text/javascript"> </script>
</head>
<body>
<div id="calander">
<script type="text/javascript">
$("document").ready( function() {
var dayData = <?php echo json_encode($dayArray); ?>; // data from database using json_encode function
var thisDate = new Date(); // present time
var thisMonth = thisDate.getMonth(); // present month
var thisYear = thisDate.getFullYear(); // present year
makeCalender(dayData, thisMonth, thisYear); // call to display calender
});
</script> <!-- end of script -->
</div> <!-- end of calender -->
</body> <!-- end of body -->
</html>
我的calender.js文件。这里一切正常,我唯一的问题是我的上一个和下一个按钮不起作用。
日历.js
function makeCalender(dayData, thisMonth, thisYear) {
// calculation for calender
// this part I make some calculation which is worked well
// now design calender table
var designTable = "";
// some calender code for designing and making calender
designTable += "<table>";
designTable += "<tr>";
// calender
designTable += "</tr>";
designTable += "<tr>";
// this prev button (before commented) doesn't work
/*designTable += "<td> <input type='button' name='prevMonth' value='&lAarr' onclick='makeCalender(" + dayDate + "," + thisMonth + "," + thisYear +")' /> </td>"; */
// this prev button also doesn't work
designTable += "<td> <input type='button' name='prev' value='prev' onclick=\'" + "makeCalender(" + dayData + ", " + prevMonth + ", " + prevYear + ");\' /> </td>";
designTable += " <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> ";
// this next button does not work
designTable += "<td> <input type='button' name='next' value='>>' onclick='alert(\"makeCalender( " + dayData + ", " + nextMonth + ", " + nextYear + " )\");' /> </td>";
// this next button (before commented) also doesn't work
/* designTable += "<td> <input type='button' name='nextMonth' value='&rAarr' onclick='makeCalender(" + dayDate + "," + nextMonth + "," + nextYear ")' /> </td>" */
designTable += "</tr>";
designTable += "</table>";
// now print this table into "calander" part in "myfile.php"
document.getElementById("calander").innerHTML = designTable;
}