用HTML加上js在网页控制台打印99乘法表
时间: 2023-12-18 12:02:37 浏览: 156
可以使用以下代码在网页控制台打印99乘法表:
```html
<!DOCTYPE html>
<html>
<head>
<title>99乘法表</title>
</head>
<body>
<button onclick="printMultiplicationTable()">打印乘法表</button>
<script>
function printMultiplicationTable() {
for (let i = 1; i <= 9; i++) {
for (let j = 1; j <= i; j++) {
console.log(j + " * " + i + " = " + (i * j));
}
}
}
</script>
</body>
</html>
```
在这个例子中,我们创建了一个按钮,当用户点击按钮时,会调用`printMultiplicationTable()`函数。该函数使用嵌套的`for`循环来生成乘法表,并通过`console.log()`将结果打印到控制台。请将以上代码复制到一个HTML文件中,并在浏览器中打开该文件。点击按钮后,乘法表将在控制台中打印出来。
相关问题
js99乘法表控制台
Sure, here is the code to generate a multiplication table from 1 to 9 in the JavaScript console:
```javascript
for (let i = 1; i <= 9; i++) {
let row = "";
for (let j = 1; j <= 9; j++) {
row += i * j + "\t";
}
console.log(row);
}
```
You can copy and run this code in the JavaScript console of your browser or any JavaScript runtime environment. It will print the multiplication table from 1 to 9 in the console.
JavaScript打印99乘法表
以下是JavaScript打印99乘法表的代码:
```javascript
for (var i = 1; i <= 9; i++) {
var row = "";
for (var j = 1; j <= i; j++) {
row += j + " x " + i + " = " + i*j + " ";
}
console.log(row);
}
```
运行以上代码,会在控制台输出99乘法表。
阅读全文