JavaScript implements the method of clicking a cell to change the background color, javascript Cell
This example describes how to change the background color by clicking cells in JavaScript. We will share this with you for your reference. The details are as follows:
<Html> <body> <table onclick = "SetColor (event) "id =" _ t "width =" 500 "border =" 0 "cellspacing =" 0 "cellpadding =" 0 "> <tr> <td width =" 93 "height = ""29" background = "hotlinkbg.gif" align = "center"> Rental Information </td> <td width = "93" height = "29" background = "hotlinkbg.gif" align =" center "> rent Information </td> <td width =" 314 "height =" 29 "background =" hotlinkbg.gif "> </td> </tr> </table> <table width = "500"> <tr> <td> aaaaa </td> <td> bbbbb </td> <td> cccc C </td> <td> ddddd </td> </tr> </table> <script tyle = "text/javascript"> var oldClr = new Array () function SetColor (e) {if (! E) e = window. event; var obj if (window. event) obj = e. srcElement else obj = e.tar getif (obj. tagName! = "TD") returnvar oldTD = obj while (obj. tagName! = "TR") obj = obj. parentNode var I for (I = 0; I <obj. cells. length; I ++) {if (obj. cells [I] = oldTD) break} var table = document. getElementById ("_ t") for (j = 0; j <table. rows. length; j ++) {// if you want to delete the colors of other columns, add the following three rows for (m = 0; m <table. rows [j]. cells. length; m ++) {table. rows [j]. cells [m]. background = oldClr [m]} // table. rows [j]. cells [I]. bgColor = table. rows [j]. cells [I]. background = "buttondomainon.gif" table. rows [j ]. Cells [I]. background = table. rows [j]. cells [I]. background = oldClr [I]? "Buttondomainon.gif": oldClr [I]} window. onload = function () {var table = document. getElementById ("_ t") for (j = 0; j <table. rows [0]. cells. length; j ++) {oldClr [j] = table. rows [0]. cells [j]. background }}</script> </body>