日期插件的包为:mydate.js.
①.:首先将日期插件的包引入到页面中
script?language="JavaScript"?src="../Inc/Js/mydate.js"/script
input?type="text"?name="starttime"?onfocus="MyCalendar.SetDate(this)"?value="?php?echo?$rq;?"
input?type="text"?name="endtime"?onfocus="MyCalendar.SetDate(this)"?value="?php?echo?$rq;?"
php
date_default_timezone_set("PRC");
$nowtime?=?time();
$rq?=?date("Y-m-d",$nowtime);
html
head
meta?name="generator"?content="FFKJ.Net"?/
link?rev="MADE"?href="mailto:FFKJ@FFKJ.Net"
title在线--后台/title
link?rel="stylesheet"?type="text/css"?href="../Skins/Admin_Style.Css"?/
/head
body
开始时间:input?type="text"?name="starttime"?onfocus="MyCalendar.SetDate(this)"?value="?php?echo?$rq;?"
结束时间:input?type="text"?name="endtime"?onfocus="MyCalendar.SetDate(this)"?value="?php?echo?$rq;?"
/body
/html
界面弹出日历框可以使用插件datepicker,也可以手写个日历插件,自定义更强一些,就是麻烦些,可以参考下我写的 ,比较简单,很方便修改;
服务端(php)通过$_GET或$_POST接收到传过来的值后,将其存入数据库.
日历插件:
在页面开发中,经常遇到需要用户输入日期的操作.通常的做法是,提供一个文本框,让用户输入,然后,编写代码验证输入的数据,检测其是否是日期型.这样比较麻烦,同时,用户输入日期的操作也不是很方便,影响用户体验.如果使用jQuery UI 中的datepicker日历插件,这些问题都可以迎刃而解.该插件调用的语法格式如下:
$(".selector").datepicker(options);
其中".selector" 表示DOM元素,一般指文本框,由于该插件的作用是提供日期选择,所以呢,常与一个文本框绑定,将选择后的日期显示在该文本框中.选项options是一个对象.
下面是一些参数:
changeMonth 设置一个布尔值,如果为true,则可以在标题处出现一个下拉选择框,可以选择月份,默认值为false
changeYear 设置一个布尔值,如果为true,则可以在标题处出现一个下拉选择框,可以选择年份,默认值为false
showButtonPanel 设置一个布尔值,如果为true, 则在日期的下面显示一个面板,其中有两个按钮;一个为"今天",另一个按键为"关闭",默认值为false,表示不显示.
closeText 设置关闭按钮上的文字信息,这项设置的前提是,showButtonPanel的值必须为true,否则显示不了效果.
showAnim 设置显示弹出或隐藏日期选择窗口的方式.可以设置的方式有,"show"、"slideDown"、"fadeIn",或者为"", 表示没有弹出日期选择窗口的方式.
showWeek 设置一个布尔值,如果为true,则可以显示每天对应的星期,默认值为false
可以通过php写href的值啊,
$year?=?(int)$_GET['year'];
echo?'a?href="index,php?year='.($year◆1).'"Next?Year/a';
calendar.class.php
代码如下:
class?Calendar?{
private?$year;?//当前的年
private?$month;?//当前的月
private?$start_weekday;?//当月的第一天对应的是周几
private?$days;?//当前月一共多少天
function?__construct(){
$this-year=isset($_GET["year"])?$_GET["year"]?:?date("Y");
$this-month=isset($_GET["month"])?$_GET["month"]?:?date("m");
$this-start_weekday=date("w",?mktime(0,?0,?0,?$this-month,?1,?$this-year));
$this-days=date("t",?mktime(0,?0,?0,?$this-month,?1,?$this-year));
}
function?out(){
echo?'table?align="center"';
$this-chageDate("test.php");
$this-weeksList();
$this-daysList();
echo?'/table';
private?function?weeksList(){
$week=array('日','一','二','三','四','五','六');
echo?'tr';
for($i=0;?$icount($week);?$i◆◆)
echo?'th?class="fontb"'.$week[$i].'/th';
echo?'/tr';
private?function?daysList(){
//输出空格(当前一月第一天前面要空出来)
for($j=0;?$j$this-start_weekday;?$j◆◆)
echo?'td?/td';
for($k=1;?$k=$this-days;?$k◆◆){
$j◆◆;
if($k==date('d'))
echo?'td?class="fontb"'.$k.'/td';
else
echo?'td'.$k.'/td';
echo?'/trtr';
//后面几个空格
private?function?prevYear($year,?$month){
$year=$year-1;
return?"year={$year}month={$month}";?
private?function?prevMonth($year,?$month){
if($month?==?1)?{
$year?=?$year?-1;
}else{
$month--;
private?function?nextYear($year,?$month){
$year?=?$year?◆?1;
private?function?nextMonth($year,?$month){
$year◆◆;
$month=1;
$month◆◆;
private?function?chageDate($url=""){
echo?'tda?href="?'.$this-prevYear($this-year,?$this-month).'"'.''.'/a/td';
echo?'tda?href="?'.$this-prevMonth($this-year,?$this-month).'"'.''.'/a/td';
echo?'form';
echo?'select?name="year"?onchange="window.location=''.$url.'?year='◆this.options[selectedIndex].value◆'month='.$this-month.''"';
$selected?=?($sy==$this-year)?"selected"?:?"";
echo?'option?'.$selected.'?value="'.$sy.'"'.$sy.'/option';
echo?'/select';
echo?'select?name="month"?onchange="window.location=''.$url.'?year='.$this-year.'month='◆this.options[selectedIndex].value"';
$selected1?=?($sm==$this-month)?"selected"?:?"";
echo?'option?'.$selected1.'?value="'.$sm.'"'.$sm.'/option';
echo?'/form';?
echo?'/td';
echo?'tda?href="?'.$this-nextYear($this-year,?$this-month).'"'.''.'/a/td';
echo?'tda?href="?'.$this-nextMonth($this-year,?$this-month).'"'.''.'/a/td';
test.php
style
table?{
.fontb?{
color:white;
background:blue;
th?{
td,th?{
text-align:center;
form?{
margin:0px;
padding:0px;
/style
include?"calendar.class.php";
$calendar=new?Calendar;
$calendar-out();
jQuery 的插件 Datepicker
这是一个非常优秀又实用的日期选择器插件,是基于Jquery开发的,您只需要将Jquery库和该插件文件导入到您的页面中,而使用很少的代码就能够为您完成非常好的效果出来!非常推荐哦! 这是一个非常优秀又实用的日期选择器插件,是基于Jquery开发的,您只需要将Jquery库和该插件文件导入到您的页面中,而使用很少的代码就能够为您完成非常好的效果出来!
以上就是土嘎嘎小编为大家整理的php日历按钮相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!