- 浏览: 7472 次
- 性别:
最新评论
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<head>
<title>日期选择器</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
body,td { font-size:9pt; }
input
{
color:333333;
font-size:9pt;
border-width:0;
padding:2;
width:20;
}
</style>
</head>
<script language=javascript>
<!--
var monthNames = new Array ( "", "1","2","3","4","5","6","7", "8", "9", "10", "11", "12" );
var endDay = new Array ( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
var dayNow = 0;
var monthNow = 0;
var yearNow = 0;
function load ( form ) {
set_month_year_now ();
var found = false;
for ( var month=0; month<form.monthList.length; month++ )
if ( form.monthList[month].text == monthNames[monthNow] ) {
form.monthList[month].selected = true;
found = true;
}
if ( !found) {
error ();
return;
}
var found = false;
for ( var year=0; year<form.yearList.length; year++ )
if ( form.yearList[year].text == yearNow ) {
form.yearList[year].selected = true;
found = true;
}
if ( !found) {
error ();
return;
}
display_month ( form );
}
function preceding_month ( form ) {
var month_selected = form.monthList.selectedIndex;
var year_selected = form.yearList.selectedIndex;
if ( !month_selected && !year_selected ) {
error ();
return;
}
if ( month_selected > 0 )
month_selected --;
else {
month_selected = 11;
year_selected --;
}
form.monthList[month_selected].selected = true;
form.yearList[year_selected].selected = true;
display_month ( form );
}
function following_month ( form ) {
var month_selected = form.monthList.selectedIndex;
var year_selected = form.yearList.selectedIndex;
if ( month_selected >= ( form.monthList.length - 1 ) && year_selected >= ( form.yearList.length - 1 ) ) {
error ();
return;
}
if ( month_selected < 11 )
month_selected ++;
else {
month_selected = 0;
year_selected ++;
}
form.monthList[month_selected].selected = true;
form.yearList[year_selected].selected = true;
display_month ( form );
}
function set_month_year_now () {
var form = document.calendar;
var now = new Date ();
monthNow = now.getMonth () + 1;
yearNow = now.getYear ();
dayNow = now.getDate();
yearNow = ( yearNow < 100 ) ? yearNow + 1900 : yearNow;
var count = 0
for (var i = yearNow-103; i < yearNow + 50; i++) {
eval("form.yearList.options[count] = new Option('"+i+"', '"+i+"')");
count++;
}
form.yearList.selectedIndex = 103;
form.yearList.length = count;
}
function error () {
alert ( "超出范围!" );
}
function display_month ( form ) {
var month = form.monthList.selectedIndex + 1;
var year = parseInt ( form.yearList.options[ form.yearList.selectedIndex].text );
var start_day = start_day_in_month ( year, month );
var count = 0;
for ( var row=0; row<6; row++) {
for ( var col=0; col<7; col++ )
{
if ( row == 0 && col < ( start_day - 1 ) )
var day = "";
else if ( count < endDay[month] )
day = ++count;
else
day = "";
form.dayBox[(row*7)+col].style.display = "";
form.dayBox[(row*7)+col].style.color = "black";
if (day == "") {
form.dayBox[(row*7)+col].style.display = "none";
} else {
form.dayBox[(row*7)+col].value = day;
if (col%7 == 0) form.dayBox[(row*7)+col].style.color = "red";
if (yearNow == year && monthNow == month && dayNow == day) form.dayBox[(row*7)+col].style.color = "blue";;
}
}
}
}
function start_day_in_month ( year, month ) {
var day, daynum, ndays, mnum;
sday = start_day_in_year ( year );
endDay[2] = ( year % 4 ) ? 28 : 29;
if ( month == 1 )
daynum = sday;
else {
ndays = sday;
for ( mnum=2; mnum<month+1; mnum++ )
ndays = ndays + endDay[mnum-1];
daynum = ndays % 7;
}
daynum = (!daynum) ? 7 : daynum;
return (daynum);
}
function start_day_in_year ( year ) {
var y, m, d;
var n;
y = year - 1; m = 13; d = 1;
n = d + 2 * m + ( Math.floor ( ( 0.6 + (m + 1) ) ) + y );
n = n + Math.floor ( ((y / 4) - Math.floor ( (y / 100 ) ) + Math.floor ( ( y / 400 ) ) ) ) + 2 ;
n = Math.floor ( ( (n / 7 - Math.floor ( (n / 7) ) ) * 7 + 0.5 ) );
return (n+1);
}
function CheckDate(strDay) {
var docFrm = document.calendar;
var choice_daynum = 0;
var current_daynum = 0;
var day_temp;
if (strDay != "") {
var strY = docFrm.yearList.value;
var strM = docFrm.monthList.value;
var curr_y = new String(yearNow);
var curr_m = new String(monthNow);
var curr_d = new String(dayNow);
if (curr_m.length == 1) curr_m = "0"+curr_m;
if (curr_d.length == 1) curr_d = "0"+curr_d;
current_daynum = new Number(curr_y + curr_m + curr_d) ;
if (strM.length == 1) strM = "0"+strM;
if (strDay.length == 1) strDay = "0"+strDay;
choice_daynum = new Number(strY + strM + strDay);
parent.window.returnValue = strY+"-"+strM+"-"+strDay; //将选择的日期传递到父窗口中
parent.window.close();
}
return false;
}
-->
</script>
<body onLoad="load(document.calendar)" topmargin="0">
<center>
<form name="calendar">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" height="24"></td>
</tr>
<tr>
<td width="205" nowrap="nowrap" align="right"><select name="yearList" onChange="display_month(this.form)">
</select>
</td>
<td width="65" nowrap="nowrap" align="left"><select name="monthList" size="1" onChange="display_month(this.form)">
<%for(int i=1;i<13;i++){%>
<option value="<%=i%>"><%=i%></option>
<%}%>
</select>
</td>
<td width="10"></td>
</tr>
<tr>
<td colspan="3" height="6"></td>
</tr>
<tr>
<td colspan="3"><table border="0" cellpadding="1" cellspacing="0" align="center">
<tr>
<td bgcolor="#82664F"><table border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#82664F" height="18">
<td width="31" align="center" nowrap="nowrap"><font color="#FF0000">日</font></td>
<td width="31" align="center" nowrap="nowrap">一</td>
<td width="31" align="center" nowrap="nowrap">二</td>
<td width="31" align="center" nowrap="nowrap">三</td>
<td width="31" align="center" nowrap="nowrap">四</td>
<td width="31" align="center" nowrap="nowrap">五</td>
<td width="31" align="center" nowrap="nowrap">六</td>
</tr>
<%for(int r=0;r<6;r++){%>
<tr bgcolor="#FFFFFF" height="18">
<%for(int d=0;d<7;d++){%>
<td align="center"><input type="text" size="2" name="dayBox" readOnly onClick="javascript:CheckDate(this.value);" onMouseOver="this.style.background='#EEEEEE'" onmouseout="this.style.background='white'">
</td>
<%}%>
</tr>
<%}%>
</table></td>
</tr>
</table></td>
</tr>
</table>
</form>
</center>
</body>
</html>
<html>
<head>
<title>日期选择器</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
body,td { font-size:9pt; }
input
{
color:333333;
font-size:9pt;
border-width:0;
padding:2;
width:20;
}
</style>
</head>
<script language=javascript>
<!--
var monthNames = new Array ( "", "1","2","3","4","5","6","7", "8", "9", "10", "11", "12" );
var endDay = new Array ( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
var dayNow = 0;
var monthNow = 0;
var yearNow = 0;
function load ( form ) {
set_month_year_now ();
var found = false;
for ( var month=0; month<form.monthList.length; month++ )
if ( form.monthList[month].text == monthNames[monthNow] ) {
form.monthList[month].selected = true;
found = true;
}
if ( !found) {
error ();
return;
}
var found = false;
for ( var year=0; year<form.yearList.length; year++ )
if ( form.yearList[year].text == yearNow ) {
form.yearList[year].selected = true;
found = true;
}
if ( !found) {
error ();
return;
}
display_month ( form );
}
function preceding_month ( form ) {
var month_selected = form.monthList.selectedIndex;
var year_selected = form.yearList.selectedIndex;
if ( !month_selected && !year_selected ) {
error ();
return;
}
if ( month_selected > 0 )
month_selected --;
else {
month_selected = 11;
year_selected --;
}
form.monthList[month_selected].selected = true;
form.yearList[year_selected].selected = true;
display_month ( form );
}
function following_month ( form ) {
var month_selected = form.monthList.selectedIndex;
var year_selected = form.yearList.selectedIndex;
if ( month_selected >= ( form.monthList.length - 1 ) && year_selected >= ( form.yearList.length - 1 ) ) {
error ();
return;
}
if ( month_selected < 11 )
month_selected ++;
else {
month_selected = 0;
year_selected ++;
}
form.monthList[month_selected].selected = true;
form.yearList[year_selected].selected = true;
display_month ( form );
}
function set_month_year_now () {
var form = document.calendar;
var now = new Date ();
monthNow = now.getMonth () + 1;
yearNow = now.getYear ();
dayNow = now.getDate();
yearNow = ( yearNow < 100 ) ? yearNow + 1900 : yearNow;
var count = 0
for (var i = yearNow-103; i < yearNow + 50; i++) {
eval("form.yearList.options[count] = new Option('"+i+"', '"+i+"')");
count++;
}
form.yearList.selectedIndex = 103;
form.yearList.length = count;
}
function error () {
alert ( "超出范围!" );
}
function display_month ( form ) {
var month = form.monthList.selectedIndex + 1;
var year = parseInt ( form.yearList.options[ form.yearList.selectedIndex].text );
var start_day = start_day_in_month ( year, month );
var count = 0;
for ( var row=0; row<6; row++) {
for ( var col=0; col<7; col++ )
{
if ( row == 0 && col < ( start_day - 1 ) )
var day = "";
else if ( count < endDay[month] )
day = ++count;
else
day = "";
form.dayBox[(row*7)+col].style.display = "";
form.dayBox[(row*7)+col].style.color = "black";
if (day == "") {
form.dayBox[(row*7)+col].style.display = "none";
} else {
form.dayBox[(row*7)+col].value = day;
if (col%7 == 0) form.dayBox[(row*7)+col].style.color = "red";
if (yearNow == year && monthNow == month && dayNow == day) form.dayBox[(row*7)+col].style.color = "blue";;
}
}
}
}
function start_day_in_month ( year, month ) {
var day, daynum, ndays, mnum;
sday = start_day_in_year ( year );
endDay[2] = ( year % 4 ) ? 28 : 29;
if ( month == 1 )
daynum = sday;
else {
ndays = sday;
for ( mnum=2; mnum<month+1; mnum++ )
ndays = ndays + endDay[mnum-1];
daynum = ndays % 7;
}
daynum = (!daynum) ? 7 : daynum;
return (daynum);
}
function start_day_in_year ( year ) {
var y, m, d;
var n;
y = year - 1; m = 13; d = 1;
n = d + 2 * m + ( Math.floor ( ( 0.6 + (m + 1) ) ) + y );
n = n + Math.floor ( ((y / 4) - Math.floor ( (y / 100 ) ) + Math.floor ( ( y / 400 ) ) ) ) + 2 ;
n = Math.floor ( ( (n / 7 - Math.floor ( (n / 7) ) ) * 7 + 0.5 ) );
return (n+1);
}
function CheckDate(strDay) {
var docFrm = document.calendar;
var choice_daynum = 0;
var current_daynum = 0;
var day_temp;
if (strDay != "") {
var strY = docFrm.yearList.value;
var strM = docFrm.monthList.value;
var curr_y = new String(yearNow);
var curr_m = new String(monthNow);
var curr_d = new String(dayNow);
if (curr_m.length == 1) curr_m = "0"+curr_m;
if (curr_d.length == 1) curr_d = "0"+curr_d;
current_daynum = new Number(curr_y + curr_m + curr_d) ;
if (strM.length == 1) strM = "0"+strM;
if (strDay.length == 1) strDay = "0"+strDay;
choice_daynum = new Number(strY + strM + strDay);
parent.window.returnValue = strY+"-"+strM+"-"+strDay; //将选择的日期传递到父窗口中
parent.window.close();
}
return false;
}
-->
</script>
<body onLoad="load(document.calendar)" topmargin="0">
<center>
<form name="calendar">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" height="24"></td>
</tr>
<tr>
<td width="205" nowrap="nowrap" align="right"><select name="yearList" onChange="display_month(this.form)">
</select>
</td>
<td width="65" nowrap="nowrap" align="left"><select name="monthList" size="1" onChange="display_month(this.form)">
<%for(int i=1;i<13;i++){%>
<option value="<%=i%>"><%=i%></option>
<%}%>
</select>
</td>
<td width="10"></td>
</tr>
<tr>
<td colspan="3" height="6"></td>
</tr>
<tr>
<td colspan="3"><table border="0" cellpadding="1" cellspacing="0" align="center">
<tr>
<td bgcolor="#82664F"><table border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#82664F" height="18">
<td width="31" align="center" nowrap="nowrap"><font color="#FF0000">日</font></td>
<td width="31" align="center" nowrap="nowrap">一</td>
<td width="31" align="center" nowrap="nowrap">二</td>
<td width="31" align="center" nowrap="nowrap">三</td>
<td width="31" align="center" nowrap="nowrap">四</td>
<td width="31" align="center" nowrap="nowrap">五</td>
<td width="31" align="center" nowrap="nowrap">六</td>
</tr>
<%for(int r=0;r<6;r++){%>
<tr bgcolor="#FFFFFF" height="18">
<%for(int d=0;d<7;d++){%>
<td align="center"><input type="text" size="2" name="dayBox" readOnly onClick="javascript:CheckDate(this.value);" onMouseOver="this.style.background='#EEEEEE'" onmouseout="this.style.background='white'">
</td>
<%}%>
</tr>
<%}%>
</table></td>
</tr>
</table></td>
</tr>
</table>
</form>
</center>
</body>
</html>
相关推荐
**JSP日历控件代码详解** 在网页开发中,日期选择控件是常见的功能之一,JSP(JavaServer Pages)作为服务器端脚本语言,提供了丰富的功能来创建动态网页。本篇将深入探讨如何在JSP中实现日历控件,并基于提供的...
【标签】"源码 工具" 提示我们这个项目可能提供了源代码,并且可以作为一个基础工具使用。这表明学习者可以查看和修改源代码,理解日历功能的实现,甚至可以根据需求扩展或优化这个简陋的日历应用。 总的来说,这个...
这个压缩包包含了一个可以复用的js日历源码,意味着开发者可以直接将这个日历组件集成到自己的JSP项目中,而无需从头开始编写代码。这大大提高了开发效率,降低了出错的可能性。 首先,我们需要了解JavaScript是...
本文将深入探讨一个基于JSP技术实现的简易日历应用源代码。该应用程序通过简单的网页展示了一个可以动态调整月份的日历视图。它允许用户选择不同的月份来查看对应月份的日历布局,并且可以通过简单的前端操作进行...
【标签】:“jsp”、“日历”、“jsp日历” 这些标签明确了我们讨论的主题:使用JSP来设计和实现一个日历功能。在Web开发中,日历通常用于显示日期、事件安排或让用户选择特定日期。而“jsp日历”标签表明我们将...
【标题】"jsp日历日程安排"是一个利用JavaServer Pages (JSP)技术构建的网页应用程序,专门用于实现日历功能和日程管理。在Web开发领域,JSP是Java平台上的一个重要组成部分,它允许开发者创建动态、交互式的网页...
至于压缩包中的"js"文件,这可能是日历插件的源代码,包含了所有实现上述功能的JavaScript代码。通常,这样的文件会包含变量声明、函数定义、事件处理程序的绑定以及可能的Ajax请求(如果需要从服务器获取或发送数据...
java源码包JSP实例源码JAVA开发源码65个合集: Java自定义光标程序源码.rar Jav动画图标源码(显示GIF图像).rar JLoading Java版的Mp3下载工具.rar JSP 动态数据菜单.rar JSP 学生管理系统(全部代码+数据库).rar ...
具体的实现细节,如数据格式化、验证和业务逻辑,需要查看源代码才能了解。 总的来说,这个示例提供了一个综合运用Jquery和Jsp进行日历显示的实践,对于学习Web前端和后端交互,以及提升动态网页开发技能很有帮助。...
【标题】"带节假日、农历的JSP/JS日历" 涉及到的知识点主要集中在前端开发和服务器端编程领域,特别是日历插件的实现与个性化功能的添加。下面将对这些知识点进行详细阐述。 首先,JSP(JavaServer Pages)是一种...
- `src` 目录是源代码目录,一般包含JSP页面、Java类、以及相关的资源文件。 在实际开发中,你需要将日历控件的库引入到`.classpath`文件中,并在`src`目录下编写JSP页面和相关的Java后台代码。完成这些步骤后,IDE...
如果是源代码,那么它可能包含了使用JSP语法编写的HTML模板和Java代码,用于生成动态日历。如果是说明文档,可能包含了如何运行此程序以及程序的工作原理。 总的来说,这个"jsp显示日历程序的小实例"涵盖了JSP基础...
学习参考,带农历的 全日历,带节假日!源码,学习!JSP,可运行!
最近项目组要做一个日程管理,原先使用fullcalendar,后面使用xgcalendar,感觉效果更好,而且日历容易定位。 因每个java项目使用的框架不一样,所以我只提取出html,没有后台java的action、service的代码。html复制...
【JSP月历时间源代码】是一个典型的Java服务器页面(JSP)开发示例,它提供了展示日期和时间,特别是包含农历节日功能的功能。在Web应用程序中,这样的功能常常用于日程管理、事件提醒或者创建用户友好的界面。下面...
在Java服务器页面(JSP)开发中,常常需要用到日历控件来提供用户友好的日期选择功能。"jsp+日历控件+好用的+两款"这个标题暗示了我们将探讨两种适用于JSP的高效日历组件。这些控件通常用于网页表单中,让用户能够...
【描述】提到“功能实现的较好”,这意味着该JSP日历程序可能已经实现了基本的日历功能,并且在用户体验、性能优化或界面设计上做得相当不错。这可能包括但不限于以下方面: 1. **动态显示日期**:JSP页面会根据...
### JSP源代码知识点概述 #### 一、JSP简介及基本概念 - **定义**:JSP(Java Server Pages)是一种基于Java技术的服务器端脚本语言,用于创建动态Web页面。它允许将HTML、CSS等静态内容与Java代码混合在一起编写。...
【标签】"源码 工具"提示这个教程可能提供了实际的源代码供学习者下载和研究,同时可能介绍了如何将这个日历功能整合到其他项目中作为一个工具。 【压缩包子文件的文件名称列表】"calendar.jsp"表明这是一个JSP文件...