我正在制作一个事件日历。我想使用按钮在 php 中回显一个函数。
我的实际代码:
日历.php
<?php include_once('functions.php'); ?>
<?php echo getCalender(); ?>
函数.php
<?php
if(isset($_POST['func']) && !empty($_POST['func'])){
switch($_POST['func']){
case 'getCalender':
getCalender($_POST['year'],$_POST['month']);
break;
case 'getEvents':
getEvents($_POST['date']);
break;
default:
break;
}
}
//Get calendar full HTML
function getCalender($year = '',$month = '')
{
$dateYear = ($year != '')?$year:date("Y");
$dateMonth = ($month != '')?$month:date("m");
$date = $dateYear.'-'.$dateMonth.'-01';
$currentMonthFirstDay = date("N",strtotime($date));
$totalDaysOfMonth = cal_days_in_month(CAL_GREGORIAN,$dateMonth,$dateYear);
$totalDaysOfMonthDisplay = ($currentMonthFirstDay == 7)?($totalDaysOfMonth):($totalDaysOfMonth + $currentMonthFirstDay);
$boxDisplay = ($totalDaysOfMonthDisplay <= 35)?35:42;
?>
<div id="calender_section">
//
}
<script type="text/javascript">
function getCalendar(target_div,year,month){
$.ajax({
type:'POST',
url:'functions.php',
data:'func=getCalender&year='+year+'&month='+month,
success:function(html){
$('#'+target_div).html(html);
}
});
}
function getEvents(date){
$.ajax({
type:'POST',
url:'functions.php',
data:'func=getEvents&date='+date,
success:function(html){
$('#event_list').html(html);
$('#event_add').slideUp('slow');
$('#event_list').slideDown('slow');
}
});
}
现在我想使用按钮来调用 getcalendar 函数。我试过这个:
日历.php
<form class="" action="" method="post">
<input type="button" value="Dhaka" onclick="<?php echo getCalender(); ?>"/>
</form>
现在这不是等待按钮点击。当我刷新页面时,即使我没有单击按钮,它也会显示日历。我该如何解决这个问题?
米脂
至尊宝的传说