1.正序
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script type="text/javascript">
//外循环控制乘法表的列数
for (var i = 1; i < 10; i++) {
//内循环控制乘法表的行数
for (j = 1; j <= i; j++) {
//输出乘法表
document.write(j + "*" + i + "=" + i * j + " ");
//加 使乘法表排列更美观
}
//每循环一次换行
document.write("</br>");
}
</script>
</html>
效果如下图
2.反序
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script type="text/javascript">
for (var i = 9; i > 0; i--) {
for (j = 1; j <= i; j++) {
document.write(j + "*" + i + "=" + i * j + " ");
}
document.write("</br>");
}
</script>
</html>
效果如下图