我正在制作一个事件日历。我想使用按钮在 php 中回显一个函数。我的实际代码:日历.php<?php include_once('functions.php'); ?> <?php echo getCalender(); ?>函数.php<?phpif(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 HTMLfunction 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>现在这不是等待按钮点击。当我刷新页面时,即使我没有单击按钮,它也会显示日历。我该如何解决这个问题?
2 回答
米脂
TA贡献1836条经验 获得超3个赞
这是functions.php的代码。你提到了 getCalender 而不是 getCalendar
<?php include_once('functions.php'); ?>
<form class="" action="" method="post">
<input type="button" value="Dhaka" onclick="getCalendar()"/>
</form>
另外,关闭functions.php 文件中getEvents 函数之后的脚本标记。
- 2 回答
- 0 关注
- 179 浏览
添加回答
举报
0/150
提交
取消