首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

javascript 日历控件的有关问题

2012-01-10 
javascript 日历控件的问题高手帮我看看错在那里给我修改一下下万分感谢!DOCTYPEhtmlPUBLIC-//W3C//DTDX

javascript 日历控件的问题
高手帮我看看   错在那里   给我修改一下下       万分感谢

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 日历生成器 </title>
<script   type= "text/javascript ">
function   funGetDaysInMonth(theMonth,theYear)
{
var   thePrevDate   =   new   Date(theYear,theMonth,0);
return   thePrevDate.getDate();
}
function   funMakeCalendar(theYear,theMonth)
{
var   myMonth   =   new   Array();
myMonth[0]   =   new   Array(7);
myMonth[1]   =   new   Array(7);
myMonth[2]   =   new   Array(7);
myMonth[3]   =   new   Array(7);
myMonth[4]   =   new   Array(7);
myMonth[5]   =   new   Array(7);
myMonth[6]   =   new   Array(7);
var   CalendarDate   =   new   Date(theYear,theMonth-1,1);
var   iDayOfFirst   =   CalendarDate.getDay();
var   iDaysInMonth   =   funGetDaysInMonth(theMonth,theYear);
var   theDate   =   1;
myMonth[0][0]   =   "Sun ";
myMonth[0][1]   =   "Mon ";
myMonth[0][2]   =   "Tue ";
myMonth[0][3]   =   "Wed ";
myMonth[0][4]   =   "Thu ";
myMonth[0][5]   =   "Fri ";
myMonth[0][6]   =   "Sat ";
for(var   i=iDayOfFirst;i <7;i++)
{
myMonth[1][i]   =   theDate;
theDate++;
}
for(var   i=2;i <7;i++)
{
for(var   j=0;j <7;j++)
{
if(theDate   <=   iDaysInMonth)
{
myMonth[i][j]   =   theDate;
theDate++;
}
}
}
return   myMonth;
}
function   funDrawCalendar(theYear,theMonth)
{
var   myMonth   =   funMakeCalendar(theYear,theMonth);
document.write( " <table   border   =   '0 '> ");
document.write( " <tr> ");
document.write( " <td   align   =   'center '>   +   myMonth[0][0]   +   </td> ");
document.write( " <td   align   =   'center '>   +   myMonth[0][1]   +   </td> ");
document.write( " <td   align   =   'center '>   +   myMonth[0][2]   +   </td> ");
document.write( " <td   align   =   'center '>   +   myMonth[0][3]   +   </td> ");
document.write( " <td   align   =   'center '>   +   myMonth[0][4]   +   </td> ");
document.write( " <td   align   =   'center '>   +   myMonth[0][5]   +   </td> ");
document.write( " <td   align   =   'center '>   +   myMonth[0][6]   +   </td> ");
document.write( " </tr> ");
for(var   i=1;i <7;i++)
{
document.write( " <tr> ");
for(var   j=0;j <7;j++)


{
document.write( " <td   id   =   '   +   rowid   +   '   align   =   'center '   valign   =   'center '   width   =   '30px '   height   =   '30px ' ");
if(myMonth[i][j]   >   0)
{
document.write(myMonth[i][j]);
}
else
{
document.write(&nbsp;);
}
document.write( " </td> ");
}
document.write( " </tr> ");
}
document.write( " </table> ");
}
function   funUpdateCalendar(theYear,theMonth)
{
myMonth   =   funMakeCalendar(theYear,theMonth);
for(var   i=1;i <7;i++)
{
for(var   j=0;j <7;j++)
{
rowid   =   "td "   +   i   +   j;
if(myMonth[i][j]   >   0)
{
document.all[rowid].children[0].innerText   =   myMonth[i][j];
}
else
{
document.all[rowid].children[0].innerText   =   " ";
}
}
}
}
</script>
</head>

<body   leftmargin= "60px ">
<form   id= "formCalender ">
<table   border= "1 ">
<tr>
<td>
<select   id= "SelectedMonth "   onchange= "funUpdateCalendar(document.getElementById( 'SelectedYear ').value,document.getElementById( 'SelectedMonth ').value) ">
<option   value= "1 "> 1月 </option>
<option   value= "2 "> 2月 </option>
<option   value= "3 "> 3月 </option>
<option   value= "4 "> 4月 </option>
<option   value= "5 "> 5月 </option>
<option   value= "6 "> 6月 </option>
<option   value= "7 "> 7月 </option>
<option   value= "8 "> 8月 </option>
<option   value= "9 "> 9月 </option>
<option   value= "10 "> 10月 </option>
<option   value= "11 "> 11月 </option>
<option   value= "12 "> 12月 </option>
</select>
&nbsp;
<select   id= "SelectedYear "   onchange= "funUpdateCalendar(document.getElementById( 'SelectedYear ').value,document.getElementById( 'SelectedMonth ').value) ">
<option   value= "1996 "> 1996 </option>
<option   value= "1997 "> 1997 </option>
<option   value= "1998 "> 1998 </option>
<option   value= "1999 "> 1999 </option>
<option   value= "2000 "> 2000 </option>
<option   value= "2001 "> 2001 </option>
<option   value= "2002 "> 2002 </option>
<option   value= "2003 "> 2003 </option>
<option   value= "2004 "> 2004 </option>
<option   value= "2005 "> 2005 </option>
<option   value= "2006 "> 2006 </option>
<option   value= "2007 "> 2007 </option>
<option   value= "2008 "> 2008 </option>
</select>
</td>
</tr>
<tr>
<script   type= "text/javascript ">


<!--
var   CurrentDate   =   new   Date();
document.getElementById( 'formCalender ').SelectedMonth.options[CurrentDate.getMonth()].seleted   =   true;
if(CurrentDate.getYear()   <   2000)
{
CurrentYear   =   "19 "   +   CurrentDate.getYear();
}
else
{
CurrentYear   =   CurrentYear.getYear();
}
for(var   i=0;i <formCalendar.SelectedYear.lenght;i++)
{
if(formCalendar.SelectedYear.option[i].value   ==   CurrentYear)
{
formCalendar.SelectedYear.option[i].selected   =   true;
}
}

var   CurrentDate   =   new   Date();
funDrawCalendar(CurrentDate.getFullYear(),CurrnetDate.getMonth()   +   1);
//-->
</script>
</tr>
</table>
</form>
</body>
</html>


[解决办法]
樓主,我幫你改好了

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 日历生成器 </title>
<script type= "text/javascript ">
function funGetDaysInMonth(theMonth,theYear)
{
var thePrevDate = new Date(theYear,theMonth,0);
return thePrevDate.getDate();
}
function funMakeCalendar(theYear,theMonth)
{
var myMonth = new Array();
myMonth[0] = new Array(7);
myMonth[1] = new Array(7);
myMonth[2] = new Array(7);
myMonth[3] = new Array(7);
myMonth[4] = new Array(7);
myMonth[5] = new Array(7);
myMonth[6] = new Array(7);
var CalendarDate = new Date(theYear,theMonth-1,1);
var iDayOfFirst = CalendarDate.getDay();
var iDaysInMonth = funGetDaysInMonth(theMonth,theYear);
var theDate = 1;
myMonth[0][0] = "Sun ";
myMonth[0][1] = "Mon ";
myMonth[0][2] = "Tue ";
myMonth[0][3] = "Wed ";
myMonth[0][4] = "Thu ";
myMonth[0][5] = "Fri ";
myMonth[0][6] = "Sat ";
for(var i=iDayOfFirst;i <7;i++)
{
myMonth[1][i] = theDate;
theDate++;
}
for(var i=2;i <7;i++)
{
for(var j=0;j <7;j++)
{
if(theDate <= iDaysInMonth)
{
myMonth[i][j] = theDate;
theDate++;
}
}
}
return myMonth;
}
function funDrawCalendar(theYear,theMonth)
{
var myMonth = funMakeCalendar(theYear,theMonth);
document.write( " <table border = '0 '> ");
document.write( " <tr> ");
document.write( " <td align = 'center '> " + myMonth[0][0] + " </td> ");
document.write( " <td align = 'center '> " + myMonth[0][1] + " </td> ");
document.write( " <td align = 'center '> " + myMonth[0][2] + " </td> ");
document.write( " <td align = 'center '> " + myMonth[0][3] + " </td> ");
document.write( " <td align = 'center '> " + myMonth[0][4] + " </td> ");
document.write( " <td align = 'center '> " + myMonth[0][5] + " </td> ");
document.write( " <td align = 'center '> " + myMonth[0][6] + " </td> ");


document.write( " </tr> ");
for(var i=1;i <7;i++)
{
document.write( " <tr> ");
for(var j=0;j <7;j++)
{
rowid = "td " + i + j;
document.write( " <td id = ' " + rowid + " ' align = 'center ' valign = 'center ' width = '30px ' height = '30px ' ");
if(myMonth[i][j] > 0)
{
document.write(myMonth[i][j]);
}
else
{
document.write( "&nbsp; ");
}
document.write( " </td> ");
}
document.write( " </tr> ");
}
document.write( " </table> ");
}
function funUpdateCalendar(theYear,theMonth)
{
myMonth = funMakeCalendar(theYear,theMonth);
for(var i=1;i <7;i++)
{
for(var j=0;j <7;j++)
{
rowid = "td " + i + j;
if(myMonth[i][j] > 0)
{
document.getElementById(rowid).innerText = myMonth[i][j];
}
else
{
document.getElementById(rowid).innerText = " ";
}
}
}
}
</script>
</head>

<body leftmargin= "60px ">
<form id= "formCalender ">
<table border= "1 ">
<tr>
<td>
<select id= "SelectedMonth " onchange= "funUpdateCalendar(document.getElementById( 'SelectedYear ').value,document.getElementById( 'SelectedMonth ').value) ">
<option value= "1 "> 1月 </option>
<option value= "2 "> 2月 </option>
<option value= "3 "> 3月 </option>
<option value= "4 "> 4月 </option>
<option value= "5 "> 5月 </option>
<option value= "6 "> 6月 </option>
<option value= "7 "> 7月 </option>
<option value= "8 "> 8月 </option>
<option value= "9 "> 9月 </option>
<option value= "10 "> 10月 </option>
<option value= "11 "> 11月 </option>
<option value= "12 "> 12月 </option>
</select>
&nbsp;
<select id= "SelectedYear " onchange= "funUpdateCalendar(document.getElementById( 'SelectedYear ').value,document.getElementById( 'SelectedMonth ').value) ">
<option value= "1996 "> 1996 </option>
<option value= "1997 "> 1997 </option>
<option value= "1998 "> 1998 </option>
<option value= "1999 "> 1999 </option>
<option value= "2000 "> 2000 </option>
<option value= "2001 "> 2001 </option>
<option value= "2002 "> 2002 </option>
<option value= "2003 "> 2003 </option>
<option value= "2004 "> 2004 </option>
<option value= "2005 "> 2005 </option>
<option value= "2006 "> 2006 </option>
<option value= "2007 "> 2007 </option>
<option value= "2008 "> 2008 </option>
</select>
</td>
</tr>
<tr>
<script type= "text/javascript ">
<!--
var CurrentDate = new Date();
document.getElementById( 'formCalender ').SelectedMonth.options[CurrentDate.getMonth()].seleted = true;
if(CurrentDate.getYear() < 2000)
{
CurrentYear = "19 " + CurrentDate.getYear();
}


else
{
CurrentYear = CurrentDate.getYear();
}
for(var i=0;i <document.getElementById( "formCalender ").SelectedYear.length;i++)
{
if(document.getElementById( "formCalender ").SelectedYear.options[i].value == CurrentYear)
{
document.getElementById( "formCalender ").SelectedYear.options[i].selected = true;
}
}

var CurrentDate = new Date();
funDrawCalendar(CurrentDate.getFullYear(),CurrentDate.getMonth() + 1);
//-->
</script>
</tr>
</table>
</form>
</body>
</html>

热点排行