Home > Web Front-end > JS Tutorial > body text

How to achieve interlaced color change using js

亚连
Release: 2018-06-23 15:48:17
Original
2101 people have browsed it

This article mainly introduces the interlaced color change effect of pure js to everyone in detail. It has certain reference value. Interested friends can refer to it.

The example in this article shares with you the js implementation of interlaced color change. The specific code is for your reference. The specific content is as follows

<script type="text/javascript">
 function createTable(){
  //创建表格
  var table = document.createElement("table");
  
  //设置表格的行数
  for(var i=0;i<4;i++){
   var tr = document.createElement("tr");
   //设置表格的列数
   for( var j=0;j<5;j++){
    var td = document.createElement("td");
    tr.appendChild(td);
    //添加文本
    var txt = document.createTextNode("wkk");
    td.appendChild(txt);
   }
   
   //判断颜色的变换
   if(i%2==0){
    //添加属性(第一种)
    tr.style.backgroundColor = "#f0f";
   } else {
    tr.style.backgroundColor = "#ff0";
   }
   
   table.appendChild(tr);
  }
  
  //添加属性(第二种)
  table.setAttribute("border","1px");
  //table.style.border = "solid 1px red";
  table.setAttribute("width","200px");
  table.setAttribute("height","100px");
  
  
  //添加到body中
  document.body.appendChild(table);
  
  
 }//create table over
 
 createTable();
</script>
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

What special data types are there in JavaScript

How to use the request network to perform request operations in the WeChat applet

Using NodeJS to write crawler examples

What problems do you encounter when using MathJax in Angular?

How to use Redux architecture in ReactNative

How to implement explicit conversion and implicit conversion in javascript

The above is the detailed content of How to achieve interlaced color change using js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template