<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script> function init(){ var tab =document.getElementById("tab") //得到表格 var rows = tab.rows for (var i = 1;i <rows.length;i++) { if (i%2 == 0) { rows[i].bgColor = "red" } else{ rows[i].bgColor = "yellow" } } } </script> </head> <body onload="init()"> <table border="1px" width="600px" id="tab"> <tr> <td> <input type = "checkbox" /> </td> <td>分类ID</td> <td>分类名称</td> <td>分类商品</td> <td>分类描述</td> <td>分类操作</td> </tr> <tr> <td> <input type = "checkbox" /> </td> <td>1</td> <td>手机数码</td> <td>华为,小米</td> <td>黑马数码智联最好</td> <td> <a href="#">修改</a> <a href="#">删除</a> </td> </tr> <tr> <td> <input type = "checkbox" /> </td> <td>2</td> <td>分类名称</td> <td>分类商品</td> <td>分类描述</td> <td>分类操作</td> </tr> <tr> <td> <input type = "checkbox" /> </td> <td>3</td> <td>分类名称</td> <td>分类商品</td> <td>分类描述</td> <td>分类操作</td> </tr> <tr> <td> <input type = "checkbox" /> </td> <td>4</td> <td>分类名称</td> <td>分类商品</td> <td>分类描述</td> <td>分类操作</td> </tr> <tr> <td> <input type = "checkbox" /> </td> <td>5</td> <td>分类名称</td> <td>分类商品</td> <td>分类描述</td> <td>分类操作</td> </tr> </table> </body> </html>