1:让每个td都有自己的随机颜色
2:需要用双循环来实现乘法表
直接上代码:
<script>
document.write('<table>');
for(var i=1;i<=9;i++){
document.write('<tr>');
for(var j=1;j<=i;j++){
var r = Math.random()*255;
var g = Math.random()*255;
var b = Math.random()*255;
document.write("<td style='background:rgb("+r+","+g+","+b+")'>");
document.write(" "+j+"*"+i+"="+i*j+" ");
document.write('</td>');
}
document.write('</tr>');
}
document.write('</table>');
</script>
效果如下: