網(wǎng)上有很多漂亮的js日歷插件 拿來做一下日期的選擇方便、漂亮,但是如果要拿來做像訂票、行程表等,這些都需要將我們的數(shù)據(jù)動態(tài)的寫入日歷中,這種就需要大量的改動,所以我們用php加js生成一個能夠高度定制的日歷 .生成日歷的代碼namespace Org\Util;class Calendar { private $year; private $month ; private $day ; private $weeks = array('日','一','二','三','四','五','六'); function __construct($options = array()) { $this->year =$options['year']; $this->month = $options['month']; $this->day = $options['day']; $vars = get_class_vars(get_class($this)); foreach ($options as $key=>$value) { if (array_key_exists($key, $vars)) { $this->$key = $value; } } } function display() { $list= ' '; $list.= $this->showChangeDate(); $list.= $this->showWeeks(); $list.= $this->showDays($this->year,$this->month,$this->day); return $list; } private function showWeeks()//生成星期 { $list = ' '; foreach($this->weeks as $title) { $list.= ''; } $list.= ''; return $list; } private function showDays($year, $month,$day) {//生成日期,具體日歷的樣式可以替換生成 $firstDay = mktime(0, 0, 0, $month, 1, $year); $starDay = date('w', $firstDay); $days = date('t', $firstDay); $list= ''; for ($i=0; $i<$starDay; $i++) { $list.= ''; } for ($j=1; $j<=$days; $j++) { $i++;$ymd = date('Y-m-d',strtotime($year.'-'.$month.'-'.$j)); $time=strtotime($year.'-'.$month.'-'.$j); if ($j == $day) { //當前日期下 $list.= ''; } else { //非當前日期下 $list.= ''; } if ($i % 7 == 0) {//一個星期結(jié)束 $list .=''; } } $list.= ''.$title.''.$j.''.$j.''.$j.'';return $list; } function showChangeDate()//點擊更換月份{ $url = basename($_SERVER['PHP_SELF']); $list=' > '; return $list; } private function preYearUrl($year,$month) { $year = ($this->year <= 1970) ? 1970 : $year - 1 ; return 'year='.$year.'&month='.$month; } private function nextYearUrl($year,$month) { $year = ($year >= 2038)? 2038 : $year + 1; return 'year='.$year.'&month='.$month; } private function preMonthUrl($year,$month) { if ($month == 1) { $month = 12; $year = ($year <= 1970) ? 1970 : $year - 1 ; } else { $month--; } return "'".$year."','".$month."'";//'year='.$year.'&month='.$month; } private function nextMonthUrl($year,$month) { if ($month == 12) { $month = 1; $year = ($year >= 2038) ? 2038 : $year + 1; }else{ $month++; } return "'".$year."','".$month."'";//'year='.$year.'&month='.$month; }}調(diào)用日歷控制器public function get_date(){ if(IS_AJAX){ $result['title']='success'; $params = array(); $year = I('get.year',date('Y')); $month = I('get.month',date('m')); $day = I('get.day',date('d')); if ($year&& $month) { $params = array( 'year' => $year, 'month' => $month, 'day' => $day, ); } $catobj = new \Org\Util\Calendar($params); // print_r($price_list); $result['content'] = $catobj->display(); $this->ajaxReturn($result); } }前端js 生成日歷chage_month(year,month,day);//當前的年月日function chage_month(year,month,day){ $.ajax({ url: "{:urlrotue('Activity/get_date')}?year="+year+"&month="+month+"&day="+day, type: "POST", cache: false, data: {}, success: function (obj) { if (obj.title == 'success') { $('#get_date').html(obj.content); } else { layer.msg(obj.msg, {icon: 5}); } }, error: function () { layer.msg('獲取日期失??!', {icon: 5}); } }); }效果:
這個樣式比較集成,只加了跳轉(zhuǎn)時間篩選功能,我們可以在日期showDays 里面添加日期的活動,門票等,看業(yè)務需求.
以上就是關(guān)于 網(wǎng)站制作系列之PHP制作日歷(東莞網(wǎng)站制作),希望對你有幫助,更多內(nèi)容關(guān)注創(chuàng)新互聯(lián)。
分享標題:網(wǎng)站制作系列之PHP制作日歷(東莞網(wǎng)站制作)
當前地址:http://jinyejixie.com/news25/324075.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、網(wǎng)站策劃、域名注冊、關(guān)鍵詞優(yōu)化、品牌網(wǎng)站制作、商城網(wǎng)站
廣告
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源:
創(chuàng)新互聯(lián)