<script language="javascript"> 
function change(){ 
this.style.backgroundColor="#C1EDFF"; 
this.style.fontSize="15px"; 
}  //改变td的背景色 function rollBack(){ 
this.style.backgroundColor="#FFFFFF"; 
this.style.fontSize=null; 
}  //恢复td的背景色 function makeTable(){ 
var curTable=document.getElementById("table"); 
curTable=curTable.lastChild; 
if(curTable.childNodes.length <3){ 
for(var trcount=0;trcount <5;trcount++){ 
var tr=document.createElement("tr"); 
for(var tdcount=0;tdcount <7;tdcount++){ 
var td=document.createElement("td"); 
td.id="td"+trcount.toString()+tdcount.toString(); 
td.onmouseover=change; 
td.onmouseout=rollBack; 
td.innerText=trcount.toString()+tdcount.toString(); 
tr.appendChild(td); 

curTable.appendChild(tr); 


}  //生成table,并且使td的id分别等于td00/td01……td12……td26,到六转0 
</script> 表格 
<input type="button" onclick="makeTable()" value="make table"/> <br /> 
<table width="500" height="300" id="table" class="calendar"> 
<tr> <td colspan="7"> <select id="year" onchange="switchDate()"> </select>&nbsp; <select id="month" onchange="switchDate()"> </select> </td> </tr> 
<tr> <td>日 </td> <td>一 </td> <td>二 </td> <td>三 </td> <td>四 </td> <td>五 </td> <td>六 </td> </tr> 
</table> 

解决方案 »

  1.   

    onmouseXX直接设置在table上就可以了,事件是会冒泡的,用event.srcElement可以获得当前移入或移出的单元格。
      

  2.   

    3楼谢谢你啊
    能不能再问一个啊
    那我怎么获得我create出来的td的id啊?那些id是不是相同的?
      

  3.   

    create的时候把给td设置上id,事件发生时直接从srcElement中读取这个id属性就好了