1.
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html xmlns="http://www.w3.org/1999/xhtml" > 5 <head> 6 <title>标题页</title> 7 <style> 8 .clickTD{ 9 background-color:#00ffff; 10 text-decoration:none;} 11 </style> 12 13 <script language="javascript"> 14 function colorChange(t) 15 { 16 for (var i=0; i<t.rows.length; i++) //遍历行 17 for (var j=0; j<t.rows[i].cells.length; j++)//遍历列 18 { 19 //触发事件的元素 20 if(window.event.srcElement==t.rows[i].cells[j]){ 21 t.rows[i].cells[j].className = "clickTD"; //改变背景色 22 } 23 } 24 } 25 </script> 26 27 </head> 28 <body> 29 <table border="1" onClick="colorChange(this)"> 30 <tr> 31 <td>第一行</td><td>第一行第二列</td> 32 </tr> 33 <tr> 34 <td>第二行</td><td>第二行第二列</td> 35 </tr> 36 </table> 37 <p> 38 </body> 39 </html>