| 项目搜索 |
| |
|
代码片段库:
查看代码片段
浏览
| 提交新的代码片段
| 创建代码包
可以选择的日历
|
类型:
Full Script |
类别:
HTML Manipulation
|
许可证:
GNU General Public License |
语言:
JavaScript
|
描述:
选择在跳出的日历窗口中可以选择一个日期
|
该代码片段的版本系列:
片段ID |
下载版本 |
提交时间 |
提交人 |
删除 |
4848 | 1.00 | 2004-08-22 10:17 | caisw | |
点击"下载版本"来下载该代码片段.
最新版本的代码片段: 1.00
<!--
// 程序功能说明:在asp中调用方法:Openurl("cl.asp"+"?obj="+theobj.form.name+"."+theobj.name,"cl","toolbar=no,menubar=no,directories=no,resizable=yes,width=185,height=155,top=150,left=450",false)
// 程序修改人:cc.cai
// 完成日期:2003/11/02
// 当前版本:V1.00
// 在以下环境测试通过
// windows XP:1、Internet Explorer 6.0
// 2、mozilla 1.03中文版
// 3、MozillaFirebird 0.7 英文版
// Redhat 9.0: 下去掉中的asp代码
// 1、mozilla 1.03中文版
// 2、MozillaFirebird 0.6 中文版
//
// -->
<html>
<head>
<title>日历</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style TYPE="text/css">
.normal{BACKGROUND: #ffffff}
.today {font-weight:bold;BACKGROUND: #6699cc}
.satday{color:green}
.sunday{color:red}
.days {font-weight:bold}
</style>
<SCRIPT type="text/javascript" LANGUAGE="JavaScript">
<!--
/*****************************************************************
* 函数名:checkBroeser() v1.0
* 功能:这是一个构造函数
* 调用举例: var cb= new checkBroeser();
* author: cc.cai by 2003/01/11
*****************************************************************/
function checkBrowser(){
// 版本信息
this.ver=navigator.appVersion;
this.dom=document.getElementById?1:0;
// 如果是ie浏览器或更高版本,ie为true,否则为false
this.ie=((navigator.appName=='Microsoft Internet Explorer')&&(parseInt(this.ver)>=4));
// 如果是Netscape4.0或更高版本,ns为true,否则为false
this.ns=((navigator.appName=='Netscape')&&(parseInt(this.ver)>=4));
// 是否为ie、Netscape中的一种
this.bw=(this.ie||this.ns);
// 返回此对象
return this;
}
var bw = new checkBrowser(); // bw.ie 用来判断是否是ie流览器
// 日历处理从这里开始
//中文月份,如果想显示英文月份,修改下面的注释
/*var months = new Array("January?, "February?, "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");*/
var months = new Array("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
//中文周 如果想显示 英文的,修改下面的注释
/*var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");*/
var days = new Array("日","一", "二", "三", "四", "五", "六");
// 下面的这段代码是返回本月的最大日期
function getDays(month, year) {
if (1 == month) // 闰年要判断
return ((0 == year % 4) && (0 != (year % 100))) || (0 == year % 400) ? 29 : 28;
else
return daysInMonth[month]; // 其它各月的天数已经在 数组daysInMonth中定义
}
//得到今天的年,月,日
function getToday() {
this.now = new Date();
this.year = this.now.getFullYear();
this.month = this.now.getMonth();
this.day = this.now.getDate();
}
var today = new getToday();
function newCalendar() { // 显示日历表中的数字
today = new getToday();
// var parseYear = parseInt(document.all.year[document.all.year.selectedIndex].text); // delete by cc.cai 2003/10/01
var objyear = document.getElementById("year"); // 2 rows added by cc.cai 2003/11/01
var parseYear = parseInt(objyear[objyear.selectedIndex].text);
// var newCal = new Date(parseYear,document.all.month.selectedIndex, 1); // delete by cc.cai 2003/11/01
var objmonth = document.getElementById("month"); // 2 rows added by cc.cai 2003/11/01
var newCal = new Date(parseYear,objmonth.selectedIndex, 1);
// alert("newCal:"+newCal);
var day = -1;
var startDay = newCal.getDay();
//alert("startDay:"+startDay);
var daily = 0;
if ((today.year == newCal.getFullYear()) &&(today.month == newCal.getMonth()))
day = today.day;
// var tableCal = document.all.calendar.tBodies.dayList; // 这句netscape不支持 modify by cc.cai 2003/11/01
var tableCal = document.getElementById("dayList");
var intDaysInMonth =getDays(newCal.getMonth(), newCal.getFullYear());
// alert("本月的天数=" + intDaysInMonth);
for (var intWeek = 0; intWeek < tableCal.rows.length;intWeek++)
for (var intDay = 0;intDay < tableCal.rows[intWeek].cells.length;intDay++) {
var cell = tableCal.rows[intWeek].cells[intDay];
if ((intDay == startDay) && (0 == daily))
daily = 1;
if(day==daily) //今天,调用今天的Class
cell.className = "today";
else if(intDay==6) //周六
cell.className = "sunday";
else if (intDay==0) //周日
cell.className ="satday";
else //平常
cell.className="normal";
if ((daily > 0) && (daily <= intDaysInMonth)) {
// cell.innerText = daily; // ns 好象不支持innerText,不知为何
cell.innerHTML = daily
daily++;
}
else
// cell.innerText = "";
cell.innerHTML = "";
}
document.getElementById("dayList").onclick=getDate; // 指明点击日期区域调用getDate
}
function getDate(evnt) { // ie 支持 event.srcElement.innerHTML 而 ns 支持 evnt.target.innerHTML
var sDate,sYear,sMonth,sDay;
// alert("这段代码处理鼠标点击的情况 " + "bw.ie=" + bw.ie + " bw.ns=" + bw.ns);
// alert(evnt); // ie 不接受这个事件
if (bw.ie) // ie
if ("TD" != event.srcElement.tagName)
{ return false;}
else
if ("" != event.srcElement.innerText)
{
// document.all.year.value + "年" + document.all.month.value + "月" + event.srcElement.innerText + "日";
// sYear = document.all.year.value; // delete by cc.cai 2003/10/01
var objyear = document.getElementById("year"); // 2 rows added by cc.cai 2003/11/01
sYear = objyear.value;
var objmonth = document.getElementById("month"); // 2 rows added by cc.cai 2003/11/01
sMonth = (objmonth.value.length==2)?objmonth.value:"0"+objmonth.value;
sDay = (event.srcElement.innerText.length==2)?event.srcElement.innerText:"0"+event.srcElement.innerText;
sDate = sYear+"/"+sMonth+"/"+sDay;
}
if (bw.ns) // ns
{ // alert ("Document got an event: " + evnt.type);
// alert ("x position is " + evnt.layerX);
// alert ("y position is " + evnt.layerY);
// alert ("Alt key was down for event." + evnt.target.tagName);
if ("TD" != evnt.target.tagName)
{ return false;}
else
if ("" != evnt.target.innerHTML)
{
// document.all.year.value + "年" + document.all.month.value + "月" + event.srcElement.innerText + "日";
// sYear = document.all.year.value; // delete by cc.cai 2003/10/01
var objyear = document.getElementById("year"); // 2 rows added by cc.cai 2003/11/01
sYear = objyear.value;
var objmonth = document.getElementById("month"); // 2 rows added by cc.cai 2003/11/01
sMonth = (objmonth.value.length==2)?objmonth.value:"0"+objmonth.value;
sDay = (evnt.target.innerHTML.length==2)?evnt.target.innerHTML:"0"+evnt.target.innerHTML;
sDate = sYear+"/"+sMonth+"/"+sDay;
}
}
// alert(sDate); // 如果是使用asp则注释本句,把以下的注释去掉
alert(sDate);
}
function monthchanged(todo) {
// alert("aa:"+ month.selectedIndex);
var newindex = month.selectedIndex;
if (todo == "prev")
newindex= (month.selectedIndex - 1) < 0?month.length - 1:month.selectedIndex - 1;
if (todo == "next")
newindex=(month.selectedIndex + 1) >= month.length ?0:month.selectedIndex + 1;
//alert("newindex:"+newindex);
//alert("newValue:"+month[newindex].value);
month[newindex].selected = true;
}
// if (bw.ns)
// document.getElementById("dayList").onclick=getDate;
//-->
</script>
</head>
<body onload="newCalendar()"> <!--onunload="window.returnValue = document.all.ret.value;" //-->
<input type="hidden" name="ret">
<table ID="calendar" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td colspan="7" align="center">
<a href="javascript:monthchanged('prev');newCalendar()" title="上月"><img src="../images/Previous.gif" border="0" WIDTH="14" HEIGHT="13"></a>
<select ID="month" onChange="newCalendar()">
<script LANGUAGE="JavaScript" type="text/javascript" title="显示月份下拉列表">
for (var intLoop = 0; intLoop < months.length; intLoop++)
document.write("<OPTION VALUE= " + (intLoop + 1) + " " + (today.month == intLoop ? "Selected" : "") + ">" + months[intLoop]);
</script>
</select>
<a href="javascript:monthchanged('next');newCalendar()" title="下一个月"><img src="../images/Next.gif" border="0" WIDTH="14" HEIGHT="13"></a>
<select ID="year" onChange="newCalendar()">
<script LANGUAGE="JavaScript" type="text/javascript" title="显示年份下拉列表,从前5年到下4年">
for (var intLoop = today.year-5; intLoop < (today.year + 4); intLoop++)
document.write("<OPTION VALUE= " + intLoop + " " + (today.year == intLoop ? "Selected" : "") + ">" + intLoop);
</script>
</select>
</td>
</tr>
<tr CLASS="days">
<script type="text/javascript" LANGUAGE="JavaScript" title="显示日历表格的头">
document.write("<TD class='satday'>" + days[0] + "</TD>");
for (var intLoop = 1; intLoop < days.length-1; intLoop++)
document.write("<TD>" + days[intLoop] + "</TD>");
document.write("<TD class='sunday'>" + days[intLoop] + "</TD>");
</script>
</tr>
</thead>
<tbody border="1" cellspacing="0" cellpadding="0" ID="dayList" ALIGN="CENTER"> <!-- ONCLICK="getDate()" -->
<script type="text/javascript" LANGUAGE="JavaScript" title="显示月份内的天数">
for (var intWeeks = 0; intWeeks < 6; intWeeks++) {
document.write("<TR style='cursor:hand'>");
for (var intDays = 0; intDays < days.length; intDays++)
document.write("<TD></TD>");
document.write("</TR>");
}
</script>
</tbody>
</table>
</body>
</html>
<script type="text/javascript" Language="JavaScript">
function Cancel() {
// document.all.ret.value = "";
document.getElementById("ret").value = "" ; // modify by cc.cai 2003/11/01
window.close();
}
</script>
如果您修改了一个代码片段并且觉得很应该让别人共享,您可以把这作为这个代码片段的最新版本提交上来. |
|