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>
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!