表行 - 给出替代颜色 [英] Table row - Giving alternate colors

查看:70
本文介绍了表行 - 给出替代颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML中,我在表中动态添加行
我需要为使用CSS的替代行提供不同的颜色
我如何才能实现?



代码:


$

b $ b

  ** var rowCount = document.getElementById(tableID)。rows.length; 
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
cell1.style.backgroundColor =yellow;
cell1.innerHTML =hey;
var cell2 = row.insertCell(1);
cell2.style.backgroundColor =green;
cell2.innerHTML =hello; **

表和填充不同的颜色到coloumns。



希望这个帮助..!
感谢


In HTML, I am adding rows dynamically in a table I need to give different colors for alternative rows using CSS How can I acheive this?

解决方案

You can also try without CSS, its simple.

Code:

    **var rowCount = document.getElementById("tableID").rows.length;
    var row = table.insertRow(rowCount);
        var cell1 = row.insertCell(0);
        cell1.style.backgroundColor = "yellow";
                    cell1.innerHTML = "hey";
                    var cell2 = row.insertCell(1);
        cell2.style.backgroundColor = "green";
                    cell2.innerHTML = "hello";**

Here its creating dynamically row for the table and filling different color to coloumns.

hope this help..!! Thanks

这篇关于表行 - 给出替代颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆