es6实现九九乘法表 并把九九乘法表放到页面上展示
时间: 2024-05-21 20:11:23 浏览: 14
// 使用嵌套循环生成九九乘法表
for(let i=1; i<=9; i++) {
let str = '';
for(let j=1; j<=i; j++) {
str += `${j}*${i}=${i*j} `;
}
console.log(str);
}
// 将九九乘法表放到页面上展示
const table = document.createElement('table');
for(let i=1; i<=9; i++) {
const row = document.createElement('tr');
for(let j=1; j<=i; j++) {
const cell = document.createElement('td');
cell.innerText = `${j}*${i}=${i*j}`;
row.appendChild(cell);
}
table.appendChild(row);
}
document.body.appendChild(table);
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)