純js實(shí)現(xiàn)隔行變色效果
本文實(shí)例為大家分享了js實(shí)現(xiàn)隔行變色的具體代碼,供大家參考,具體內(nèi)容如下
<script type="text/javascript"> function createTable(){ //創(chuàng)建表格 var table = document.createElement("table"); //設(shè)置表格的行數(shù) for(var i=0;i<4;i++){ var tr = document.createElement("tr"); //設(shè)置表格的列數(shù) 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>
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章

js編碼之encodeURIComponent使用介紹(asp,php)

tween.js緩動(dòng)補(bǔ)間動(dòng)畫算法示例

js 采用delete實(shí)現(xiàn)繼承示例代碼

javascript實(shí)現(xiàn)無限級(jí)select聯(lián)動(dòng)菜單

uni-app分包項(xiàng)目實(shí)戰(zhàn)總結(jié)

原生JS操作網(wǎng)頁給p元素添加onclick事件及表格隔行變色

讓網(wǎng)站自動(dòng)生成章節(jié)目錄索引的多個(gè)js代碼