用微信小程序代码写一个九九乘法表
时间: 2023-06-08 18:04:26 浏览: 108
JavaScript 实现九九乘法表
可以的,以下是用微信小程序代码写的九九乘法表:
<!-- index.wxml -->
<view class="container">
<view class="row" wx:for="{{rows}}" wx:key="{{index}}">
<view class="cell" wx:for="{{row}}" wx:key="{{index}}">
{{item}}
</view>
</view>
</view>
// index.js
Page({
data: {
rows: []
},
onLoad: function () {
this.generateTable()
},
generateTable: function () {
const rows = []
for (let i = 1; i <= 9; i++) {
const row = []
for (let j = 1; j <= i; j++) {
row.push(`${j}x${i}=${i * j}`)
}
rows.push(row)
}
this.setData({
rows
})
}
})
/* index.wxss */
.container {
display: flex;
flex-direction: column;
align-items: center;
}
.row {
display: flex;
flex-direction: row;
justify-content: center;
margin-bottom: 10rpx;
}
.cell {
padding: 10rpx;
font-size: 24rpx;
text-align: center;
border: 1rpx solid black;
}
阅读全文