wfcvn 发表于 2007-4-27 11:23:19

***时间日期***再放上一个万年历脚本

把下列代码加到网页的<body></body>标签之间 从google下载我的照片管理软件
要完成此效果需要两个步骤

第一步:把如下代码加入到<body>区域中

<script language="javascript">
<!-- begin
function settoday() {
var now   = new date();
var day   = now.getdate();
var month = now.getmonth();
var year= now.getyear();
if (year < 2000)   
year = year + 1900;
this.focusday = day;
document.calcontrol.month.selectedindex = month;
document.calcontrol.year.value = year;
displaycalendar(month, year);
}
function isfourdigityear(year) {
if (year.length != 4) {
alert ("sorry, the year must be four-digits in length.");
document.calcontrol.year.select();
document.calcontrol.year.focus();
} else { return true; }
}
function selectdate() {
var year= document.calcontrol.year.value;
if (isfourdigityear(year)) {
var day   = 0;
var month = document.calcontrol.month.selectedindex;
displaycalendar(month, year);
    }
}

function setpreviousyear() {
var year= document.calcontrol.year.value;
if (isfourdigityear(year)) {
var day   = 0;
var month = document.calcontrol.month.selectedindex;
year--;
document.calcontrol.year.value = year;
displaycalendar(month, year);
   }
}
function setpreviousmonth() {
var year= document.calcontrol.year.value;
if (isfourdigityear(year)) {
var day   = 0;
var month = document.calcontrol.month.selectedindex;
if (month == 0) {
month = 11;
if (year > 1000) {
year--;
document.calcontrol.year.value = year;
}
} else { month--; }
document.calcontrol.month.selectedindex = month;
displaycalendar(month, year);
   }
}
function setnextmonth() {
var year= document.calcontrol.year.value;
if (isfourdigityear(year)) {
var day   = 0;
var month = document.calcontrol.month.selectedindex;
if (month == 11) {
month = 0;
year++;
document.calcontrol.year.value = year;
} else { month++; }
document.calcontrol.month.selectedindex = month;
displaycalendar(month, year);
   }
}
function setnextyear() {
var year = document.calcontrol.year.value;
if (isfourdigityear(year)) {
var day = 0;
var month = document.calcontrol.month.selectedindex;
year++;
document.calcontrol.year.value = year;
displaycalendar(month, year);
   }
}
function displaycalendar(month, year) {      
month = parseint(month);
year = parseint(year);
var i = 0;
var days = getdaysinmonth(month+1,year);
var firstofmonth = new date (year, month, 1);
var startingpos = firstofmonth.getday();
days += startingpos;
document.calbuttons.calpage.value=   " su mo tu we th fr sa";
document.calbuttons.calpage.value += "\n --------------------";
for (i = 0; i < startingpos; i++) {
if ( i%7 == 0 ) document.calbuttons.calpage.value += "\n ";
document.calbuttons.calpage.value += "   ";
}
for (i = startingpos; i < days; i++) {
if ( i%7 == 0 ) document.calbuttons.calpage.value += "\n ";
if (i-startingpos+1 < 10)
document.calbuttons.calpage.value += "0";
document.calbuttons.calpage.value += i-startingpos+1;
document.calbuttons.calpage.value += " ";
}
for (i=days; i<42; i++){
if ( i%7 == 0 ) document.calbuttons.calpage.value += "\n ";
document.calbuttons.calpage.value += "   ";
}
document.calcontrol.go.focus();
}
function getdaysinmonth(month,year){
var days;
if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)days=31;
else if (month==4 || month==6 || month==9 || month==11) days=30;
else if (month==2){
if (isleapyear(year)) { days=29; }
else { days=28; }
}
return (days);
}
function isleapyear (year) {
if (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0)) {
return (true);
} else { return (false); }
}
// end -->
</script>
<center>
<h2>万年历</h2>
<form name="calcontrol" onsubmit="return false;">
<table cellpadding=0 cellspacing=0 border=0>
<tr><td colspan=7>
<center>
<select name="month" onchange="selectdate()">
<option>一月
<option>二月
<option>三月
<option>四月
<option>五月
<option>六月
<option>七月
<option>八月
<option>九月
<option>十月
<option>十一月
<option>十二月
</select>
<input name="year" type=text size=4 maxlength=4>
<input type="button" name="go" value="创建" onclick="selectdate()">
</center>
</td>
</tr>
</form>
<form name="calbuttons">

<tr><td align="center"><textarea font="courier" name="calpage" wrap=no rows=8 cols=22>
   

第二步:把“onload="settoday()"”加在标记里例如:
      











-- ------ - -------- ---------------------


http:/ /www. huoyue.com.cn 活跃网,活跃人群的论坛,访问活 跃网,将给您带来意想不到的收获,还可以免费为 您开论坛,让您免费拥有与朋友、网友交流的论坛。你是年轻人 吗?你活跃 你就上!
页: [1]
查看完整版本: ***时间日期***再放上一个万年历脚本