Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何交替表格颜色并保持主体背景?_Javascript_Html_Css_Html Table - Fatal编程技术网

Javascript 如何交替表格颜色并保持主体背景?

Javascript 如何交替表格颜色并保持主体背景?,javascript,html,css,html-table,Javascript,Html,Css,Html Table,(运行代码PLS) 如何将黑色块颜色更改为白色,与表的其他部分颜色相同 <body style="background-color:black;"> <div style="color: white;"> <script> var colors = ["#f2f2f2", "#919191"]; var colorIndex = 0; function ch

(运行代码PLS) 如何将黑色块颜色更改为白色,与表的其他部分颜色相同

<body style="background-color:black;">
<div style="color: white;">
<script>
    var colors = ["#f2f2f2", "#919191"];
    var colorIndex = 0;
    function changeColor() {
        var col = document.getElementById("body");
        if( colorIndex >= colors.length ) {
            colorIndex = 0;
        }
        col.style.backgroundColor = colors[colorIndex];
        colorIndex++;
    }
</script>
<style>
.bouton{
  width: 200px;
  border: 3px solid black;
  border-radius: 15px;
}
table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

td, th {
  border: 1px solid #ebebeb;
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: white;
}
td:nth-child(even) {
  background-color: white;
}
</style>

<table>
<tr>
<td>
<xmp>
<!--...-->
</xmp>
</td>
<td>
<xmp>
Defines a comment
</xmp>
</td>
</tr>
<tr>
<td>
<xmp>
<!DOCTYPE>
</xmp>
</td>
<td>
<xmp>
Defines the document type
</xmp>
</td>
</tr>
<tr>
<td>
<xmp>
<a>
</xmp>
</td>
<td>
<xmp>
Defines a hyperlink
</xmp>
</td>
</tr>
<tr>
<td>
<xmp>
<abbr>
</xmp>
</td>
<td>
<xmp>
Defines an abbreviation or an acronym
</xmp>
</td>
</tr>

变量颜色=[“#f2f2f2”、“#919191”];
var指数=0;
函数changeColor(){
var col=document.getElementById(“主体”);
如果(colorIndex>=colors.length){
颜色指数=0;
}
col.style.backgroundColor=颜色[颜色索引];
彩色索引++;
}
鲍顿先生{
宽度:200px;
边框:3倍纯黑;
边界半径:15px;
}
桌子{
字体系列:arial,无衬线;
边界塌陷:塌陷;
宽度:100%;
}
td,th{
边框:1px实心#ebebebeb;
文本对齐:左对齐;
填充:8px;
}
tr:n个孩子(偶数){
背景色:白色;
}
td:n个孩子(偶数){
背景色:白色;
}
定义注释
定义文档类型
定义超链接
定义缩写或首字母缩略词

不要对这篇随机文本进行尝试,它会让我发布原因:YF9YWE yf W87F78WE f WEF 7 ywe f87weyf我们FWEF87WEF87YEWQFWEF q FQWEFYF WUQYDFEW w df ywdq f87wd8 fw8df w w w w w w w w w fywf w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w这两条规则:

tr:nth-child(even) {
  background-color: white;
}
td:nth-child(even) {
  background-color: white;
}


这就是为什么我如此喜欢这个论坛,tnx如此之多,兄弟
tr {
  background-color: white;
}
td {
  background-color: white;
}