input添加日历控件_将控件添加到PHP日历

这篇博客介绍了如何在PHP日历中添加控件,包括“下个月”、“上个月”按钮以及月份/年份的下拉选择,以便用户无需等到下个月就能查看其他日期的事件。此外,文章讨论了不在PHP函数内部包含这些控件的原因,以方便自定义样式。最后,作者鼓励读者思考如何添加更多功能,如AJAX方法。
摘要由CSDN通过智能技术生成

input添加日历控件

PHP / XHTML / CSS Calendar

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方法怎么样? 分享他们!

翻译自: https://davidwalsh.name/php-calendar-controls

input添加日历控件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值