欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于JavaScript實(shí)現(xiàn)表格隔行換色

 更新時(shí)間:2020年05月08日 15:47:57   作者:朱李洛克  
這篇文章主要介紹了基于JavaScript實(shí)現(xiàn)表格隔行換色,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

表格隔行換色

需求分析

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

技術(shù)分析

table對(duì)象 集合 cells[]:返回包含表格中所有單元格的一個(gè)數(shù)組。 rows[]:返回包含表格中所有行的一個(gè)數(shù)組。 tBodies[]:返回包含表格中所有tbody 的一個(gè)數(shù)組。

步驟分析

確定事件: 文檔加載完成 onload 2. 事件要觸發(fā)函數(shù): init() 3. 函數(shù):操作頁(yè)面的元素 要操作表格中每一行 動(dòng)態(tài)的修改行的背景顏色
代碼實(shí)現(xiàn)

<!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;
      //便利所有的行,然后根據(jù)奇數(shù) 偶數(shù)
      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" 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>手機(jī)數(shù)碼</td>
    <td>華為,小米,尼康</td>
    <td>黑馬數(shù)碼產(chǎn)品質(zhì)量最好</td>
    <td>
      <a href="#" 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="#" 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>這里面的充氣電動(dòng)硅膠的</td>
    <td><a href="#" 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="#" 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>聯(lián)想,小米</td>
    <td>筆記本特賣</td>
    <td><a href="#" 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="#" 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="#" 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="#" 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="#" 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="#" 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>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • javascript對(duì)象的創(chuàng)建和訪問(wèn)

    javascript對(duì)象的創(chuàng)建和訪問(wèn)

    這篇文章主要為大家詳細(xì)介紹了javascript對(duì)象的創(chuàng)建和訪問(wèn)實(shí)現(xiàn)方法,感興趣的小伙伴們可以參考一下
    2016-03-03
  • 原生js拖拽(第一課 未兼容)拖拽思路

    原生js拖拽(第一課 未兼容)拖拽思路

    第一步點(diǎn)擊需要拖動(dòng)的元素,在點(diǎn)擊下的元素被選中,進(jìn)行move移動(dòng),當(dāng)鼠標(biāo)彈起的時(shí)候,停止動(dòng)作.點(diǎn)擊元素oDIV的時(shí)候,可用的是oDIV區(qū)域,而move和up則是全局區(qū)域
    2013-03-03
  • JS Input里添加小圖標(biāo)的兩種方法

    JS Input里添加小圖標(biāo)的兩種方法

    大家在做網(wǎng)站的時(shí)候,經(jīng)常需要在input里面添加小圖標(biāo)功能,看似功能很簡(jiǎn)單,但是實(shí)現(xiàn)起來(lái)還是有點(diǎn)技巧的,下面小編給大家介紹下JS Input里添加小圖標(biāo)的兩種方法,需要的朋友參考下吧
    2017-11-11
  • JS實(shí)現(xiàn)物體帶緩沖的間歇運(yùn)動(dòng)效果示例

    JS實(shí)現(xiàn)物體帶緩沖的間歇運(yùn)動(dòng)效果示例

    這篇文章主要介紹了JS實(shí)現(xiàn)物體帶緩沖的間歇運(yùn)動(dòng)效果,可實(shí)現(xiàn)物體定時(shí)間歇運(yùn)動(dòng)的功能,涉及javascript定時(shí)器、數(shù)學(xué)運(yùn)算及頁(yè)面元素動(dòng)態(tài)修改的相關(guān)操作技巧,需要的朋友可以參考下
    2016-12-12
  • ES6 Set結(jié)構(gòu)的應(yīng)用實(shí)例分析

    ES6 Set結(jié)構(gòu)的應(yīng)用實(shí)例分析

    這篇文章主要介紹了ES6 Set結(jié)構(gòu)的應(yīng)用,結(jié)合實(shí)例形式分析了ES6 set結(jié)構(gòu)的功能、特點(diǎn)、常見(jiàn)用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2019-06-06
  • uniapp中安裝axios并解決跨域問(wèn)題小結(jié)

    uniapp中安裝axios并解決跨域問(wèn)題小結(jié)

    跨域(Cross-Origin)是指在瀏覽器中,當(dāng)前網(wǎng)頁(yè)的協(xié)議、域名或端口與請(qǐng)求目標(biāo)的協(xié)議、域名或端口不相同,即存在跨域請(qǐng)求的情況,這篇文章主要介紹了uniapp中安裝axios并解決跨域問(wèn)題小結(jié),需要的朋友可以參考下
    2024-05-05
  • JavaScript NaN和Infinity特殊值 [譯]

    JavaScript NaN和Infinity特殊值 [譯]

    本文要講的是兩個(gè)特殊值,NaN和Infinity,返回這兩個(gè)值的操作通常都應(yīng)該返回正常的數(shù)字
    2012-09-09
  • js實(shí)現(xiàn)Select列表內(nèi)容自動(dòng)滾動(dòng)效果代碼

    js實(shí)現(xiàn)Select列表內(nèi)容自動(dòng)滾動(dòng)效果代碼

    這篇文章主要介紹了js實(shí)現(xiàn)Select列表內(nèi)容自動(dòng)滾動(dòng)效果的方法,涉及javascript簡(jiǎn)單遞歸調(diào)用遍歷select及時(shí)間函數(shù)的相關(guān)使用技巧,需要的朋友可以參考下
    2015-08-08
  • 一起來(lái)了解JavaScript的變量作用域

    一起來(lái)了解JavaScript的變量作用域

    這篇文章主要為大家詳細(xì)介紹了JavaScript變量作用域,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-03-03
  • javascript中createElement的兩種創(chuàng)建方式

    javascript中createElement的兩種創(chuàng)建方式

    這篇文章主要介紹了javascript中createElement的兩種創(chuàng)建方式,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-05-05

最新評(píng)論