<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>JS Table</title> <style> .blue { background:blue; color:#fff; } .red { background:red; color:#fff; } </style> </head> <body> <table> <tr> <th>Column One</th> <th>Column Two</th> <th>Column Three</th> <th>Column Four</th> </tr> <tr> <td>Data One</td> <td>Data Two</td> <td>Data Three</td> <td>Data Four</td> </tr> <tr> <td>Data Five</td> <td>Data Six</td> <td>Data Seven</td> <td>Data Eight</td> </tr> </table> <script> var t = document.getElementById("t"); //下面是 js 控制表格行列 t.rows[1].cells[1].className= "blue"; t.rows[2].cells[3].className = "red"; </script> </body></html>
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>JS Table</title> <style> .blue { background:blue; color:#fff; } .red { background:red; color:#fff; } </style> </head> <body> <table> <tr> <th>Column One</th> <th>Column Two</th> <th>Column Three</th> <th>Column Four</th> </tr> <tr> <td>Data One</td> <td>Data Two</td> <td>Data Three</td> <td>Data Four</td> </tr> <tr> <td>Data Five</td> <td>Data Six</td> <td>Data Seven</td> <td>Data Eight</td> </tr> </table> <script> var t = document.getElementById("t"); //下面是 js 控制表格行列 t.rows[1].cells[1].className= "blue"; t.rows[2].cells[3].className = "red"; </script> </body></html>