久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

基于JavaScript實現表格隔行換色

瀏覽:103日期:2023-10-29 15:29:11

表格隔行換色

需求分析

我們商品分類的信息太多,如果每一行都顯示同一個顏色的話會讓人看的眼花,為了提高用戶體驗,減少用戶看錯的情況,需要對表格進行隔行換色

技術分析

table對象 集合 cells[]:返回包含表格中所有單元格的一個數組。 rows[]:返回包含表格中所有行的一個數組。 tBodies[]:返回包含表格中所有tbody 的一個數組。

步驟分析

確定事件: 文檔加載完成 onload 2. 事件要觸發函數: init() 3. 函數:操作頁面的元素 要操作表格中每一行 動態的修改行的背景顏色代碼實現

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Title</title> <script > function init(){ //得到表格 var tab = document.getElementById('tab'); //得到表格中每一行 var rows = tab.rows; //便利所有的行,然后根據奇數 偶數 for(var i=1; i < rows.length; i++){var row = rows[i]; //得到其中的某一行if(i%2==0){ row.bgColor = 'yellow';}else{ row.bgColor = 'red'} } } </script></head><body onload='init()'><table border='1px' 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='http://m.baoyu77737.com/bcjs/16677.html#' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' >修改</a>|<a href='http://m.baoyu77737.com/bcjs/16677.html#' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' >刪除</a> </td> </tr> <tr> <td> <input type='checkbox'/> </td> <td>2</td> <td>成人用品</td> <td>充氣的</td> <td>這里面的充氣電動硅膠的</td> <td><a href='http://m.baoyu77737.com/bcjs/16677.html#' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' >修改</a>|<a href='http://m.baoyu77737.com/bcjs/16677.html#' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' >刪除</a></td> </tr> <tr> <td> <input type='checkbox'/> </td> <td>3</td> <td>電腦辦公</td> <td>聯想,小米</td> <td>筆記本特賣</td> <td><a href='http://m.baoyu77737.com/bcjs/16677.html#' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' >修改</a>|<a href='http://m.baoyu77737.com/bcjs/16677.html#' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' >刪除</a></td> </tr> <tr> <td> <input type='checkbox'/> </td> <td>4</td> <td>饞嘴零食</td> <td>辣條,麻花,黃瓜</td> <td>年貨</td> <td><a href='http://m.baoyu77737.com/bcjs/16677.html#' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' >修改</a>|<a href='http://m.baoyu77737.com/bcjs/16677.html#' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' >刪除</a></td> </tr> <tr> <td> <input type='checkbox'/> </td> <td>5</td> <td>床上用品</td> <td>床單,被套,四件套</td> <td>都是套子</td> <td><a href='http://m.baoyu77737.com/bcjs/16677.html#' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' >修改</a>|<a href='http://m.baoyu77737.com/bcjs/16677.html#' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' >刪除</a></td> </tr></table></body></html>

基于JavaScript實現表格隔行換色

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 松溪县| 津市市| 东光县| 普兰店市| 眉山市| 咸阳市| 株洲市| 驻马店市| 龙山县| 乐陵市| 双城市| 双流县| 武平县| 宁陵县| 克东县| 广南县| 松原市| 花垣县| 江口县| 寿阳县| 常州市| 临朐县| 内乡县| 山东省| 栾城县| 五家渠市| 万全县| 隆林| 曲沃县| 沙湾县| 宣威市| 阆中市| 永兴县| 商城县| 阿拉善右旗| 扎兰屯市| 通海县| 江阴市| 长武县| 海盐县| 崇信县|