js新增不同顏色的行練習

js新增不同顏色的行練習
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function create()
{
var mtable=document.getElementById("mytable");
for(var i=0;i<10;i  )
{
var newrow=mtable.insertRow();
var cell=newrow.insertCell();
cell.innerHTML="line" i;
if(i%2==0)
{
newrow.style.backgroundColor="aqua";
}
else
{
newrow.style.backgroundColor="#FF0000";
}
}
}
</script>
</head>
<body onload="create()">
<table id="mytable"></table>
</body>
</html>

執行結果如下: