我正在制作一個(gè)事件日歷。我想使用按鈕在 php 中回顯一個(gè)函數(shù)。我的實(shí)際代碼:日歷.php<?php include_once('functions.php'); ?> <?php echo getCalender(); ?>函數(shù).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'); } }); }現(xiàn)在我想使用按鈕來調(diào)用 getcalendar 函數(shù)。我試過這個(gè):日歷.php <form class="" action="" method="post"> <input type="button" value="Dhaka" onclick="<?php echo getCalender(); ?>"/> </form>現(xiàn)在這不是等待按鈕點(diǎn)擊。當(dāng)我刷新頁(yè)面時(shí),即使我沒有單擊按鈕,它也會(huì)顯示日歷。我該如何解決這個(gè)問題?
2 回答

米脂
TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超3個(gè)贊
這是functions.php的代碼。你提到了 getCalender 而不是 getCalendar
<?php include_once('functions.php'); ?>
<form class="" action="" method="post">
<input type="button" value="Dhaka" onclick="getCalendar()"/>
</form>
另外,關(guān)閉functions.php 文件中g(shù)etEvents 函數(shù)之后的腳本標(biāo)記。
- 2 回答
- 0 關(guān)注
- 210 瀏覽
添加回答
舉報(bào)
0/150
提交
取消