input添加日历控件
I showed you how to create a PHP calendar last week. The post was very popular so I wanted to follow it up with another post about how you can add controls to the calendar. After all, you don't want your users to need to wait until the next month to see events outside of the current month, right? Now we'll add "Next Month", "Previous Month", and month/year dropdown controls to the calendar.
我上周向您展示了如何创建PHP日历 。 该帖子非常受欢迎,因此我想在其后跟另一篇有关如何向日历添加控件的帖子。 毕竟,您不希望用户需要等到下个月才能看到当月以外的事件,对吗? 现在,我们将“下个月”,“上个月”和月/年下拉控件添加到日历中。
PHP => HTML (The PHP => HTML)
/* date settings */
$month = (int) ($_GET['month'] ? $_GET['month'] : date('m'));
$year = (int) ($_GET['year'] ? $_GET['year'] : date('Y'));
/* select month control */
$select_month_control = '<select name="month" id="month">';
for($x = 1; $x <= 12; $x++) {
$select_month_control.= '<option value="'.$x.'"'.($x != $month ? '' : ' selected="selected"').'>'.date('F',mktime(0,0,0,$x,1,$year)).'</option>';
}
$select_month_control.= '</select>';
/* select year control */
$year_range = 7;
$select_year_control = '<select name="year" id="year">';
for($x = ($year-floor($year_range/2)); $x <= ($year+floor($year_range/2)); $x++) {
$select_year_control.= '<option value="'.$x.'"'.($x != $year ? '' : ' selected="selected"').'>'.$x.'</option>';
}
$select_year_control.= '</select>';
/* "next month" control */
$next_month_link = '<a href="?month='.($month != 12 ? $month + 1 : 1).'&year='.($month != 12 ? $year : $year + 1).'" class="control">Next Month >></a>';
/* "previous month" control */
$previous_month_link = '<a href="?month='.($month != 1 ? $month - 1 : 12).'&year='.($month != 1 ? $year : $year - 1).'" class="control"><< Previous Month</a>';
/* bringing the controls together */
$controls = '<form method="get">'.$select_month_control.$select_year_control.' <input type="submit" name="submit" value="Go" /> '.$previous_month_link.' '.$next_month_link.' </form>';
echo $controls;
I wont explain the code because it's boring and simple but you may be wondering why I didn't include the controls within the PHP function. Since you may or may not want the controls and will want to style them differently, placing the controls within the PHP function would be a bad idea.
我不会解释代码,因为它既无聊又简单,但是您可能想知道为什么我没有在PHP函数中包含控件。 由于您可能想要也可能不想要这些控件,并且希望以不同的方式设置它们的样式,因此将控件放置在PHP函数中将不是一个好主意。
Can you think of any other controls to add to the calendar? How about an AJAX method? Share them!
您能想到要添加到日历的任何其他控件吗? AJAX方法怎么样? 分享他们!
input添加日历控件