问个javascript的简单问题
载入一个页面的时候,页面上有个表格
---------------------------------
2007-04 | 2007-05 | 2007-06 | 2007-07 | 2007-08 | 2007-09 | 2007-10 |
---------------------------------
怎么使得表格上面显示如上的内容呢?
就首先是当前月,后面的单元格里是当前月依次后推6个月
用javascript怎么写呢?
各位高手帮忙啊!
------解决方案-------------------- <script language= "JavaScript ">
<!--
var date1 = new Date();
for(var i = 0; i <= 6; i ++){
var date_temp = new Date(date1.getFullYear() , (date1.getMonth() + i));
var date_html = date_temp.getFullYear() + "- " + (date_temp.getMonth() + 1);
alert(date_html);
}
//-->
</script>
------解决方案-------------------- <html>
<body>
<table name= "table1 " id= "table1 ">
<tr>
<td> | </td>
<td> | </td>
<td> | </td>
<td> | </td>
<td> | </td>
<td> | </td>
<td> | </td>
</tr>
</table>
<script language= "JavaScript ">
<!--
var date=new Date();
var year=date.getYear();
var month=date.getMonth()+1;
var table=document.getElementById( "table1 ");
var cellLength=table.rows[0].cells.length;
for(var i=0;i <cellLength;i++)
{
table.rows[0].cells[i].innerText+=year+ "- "+(month+i);
}
//-->
</script>
</body>
</html>
------解决方案-------------------- <script>
window.onload=function(){
var tab=document.getElementById( "tab ");
var time = new Date();
var year = time.getFullYear();
var month = time.getMonth()+1;//返回0-11,所以+1
for(var i=0;i <7;i++){
var cell=tab.rows[0].cells[i];
var m=month+i;
var y=year;
if(m> 12){y++;m++;}
cell.innerHTML=y+ "- "+(m%13);
}
}
</script>
<table id= "tab ">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
------解决方案-------------------- <html>
<head>
</head>
<body>
<script>
window.onload=function(){
var date1 = new Date();
for(var i = 0; i <= 6; i ++){
var date_temp = new Date(date1.getFullYear() , (date1.getMonth() + i));
var date_html = date_temp.getFullYear() + "- " + (date_temp.getMonth() + 1);
document.getElementById( "tab ").rows(0).cells(i).innerText = date_html;
}
}
</script>
<table id= "tab " border=1>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>