- 按下+1按钮,系统会自动加一并显示:
- 按下-1按钮,系统会自动减一并显示:
- 按下*2按钮,系统会自动乘二并显示:
- 按下/2按钮,系统会自动除以二并显示:
根据上述基本操作,可以实现类似于计算器的功能。
in.js
Page({
/**
* 页面的初始数据
*/
data: {
num:0 //设定初值,方便在页面上显示
},
onLoad: function (options) {
},
inc1: function(event){
var that=this
this.setData({
num:that.data.num+1
})
},
dec1: function(event){
var that=this
this.setData({
num:that.data.num-1
})
},
mul2: function(event){
var that=this
this.setData({
num:that.data.num*2
})
},
div2: function(event){
var that=this
this.setData({
num:that.data.num/2
})
},
})
in.json
{
"usingComponents": {}
}
in.wxml
<view class="background">
<text class="title">{{num}}</text>
<!-- <text class="text">{{infomation}}</text> -->
</view>
<view class="btn1">
<text bindtap="inc1">加一</text>
</view>
<view class="btn2">
<text bindtap="dec1">减一</text>
</view>
<view class="btn3">
<text bindtap="mul2">乘二</text>
</view>
<view class="btn4">
<text bindtap="div2">除二</text>
</view>
in.wxss
.background{
display: flex;
flex-direction: column;
justify-content: center;
background-color: rgb(255, 255, 255);
width: 90%;
border-radius: 20rpx;
margin-top: 50rpx;
margin-left: auto;
margin-right: auto;
box-shadow:0rpx 0rpx 20rpx 1rpx gray;
}
.title{
margin: auto;
margin-top: 50rpx;
color: red;
font-size: 130%;
}
.btn1{
font-size: 13pt;
height: 55rpx;
background: #7B68EE;
color: black;
text-align: center;
border-radius: 50px;
margin: 10% 20% 10% 20%;
}
.btn2{
font-size: 13pt;
height: 55rpx;
background: #00FA9A;
color: black;
text-align: center;
border-radius: 50px;
margin: 10% 20% 10% 20%;
}
.btn3{
font-size: 13pt;
height: 55rpx;
background: #F0E68C;
color: black;
text-align: center;
border-radius: 30px;
margin: 10% 20% 10% 20%;
}
.btn4{
font-size: 13pt;
height: 55rpx;
background: #FF4500;
color: black;
text-align: center;
border-radius: 30px;
margin: 10% 20% 10% 20%;
}
不错~