위 챗 애플 릿 계산기 인 스 턴 스 상세 설명
index.wxml
<view class="content">
<view class="num">{{num}}</view>
<view class="operotor">{{op}}</view>
</view>
<view class="entry">
<view>
<view class="item" bindtap="resetBtn">c</view>
<view class="item" bindtap="delBtn">DEL</view>
<view class="item" bindtap="opBtn" data-val="%">%</view>
<view class="item" bindtap="opBtn" data-val="/">÷</view>
</view>
<view>
<view class="item" bindtap="numBtn" data-val="7">7</view>
<view class="item" bindtap="numBtn" data-val="8">8</view>
<view class="item" bindtap="numBtn" data-val="9">9</view>
<view class="item" bindtap="opBtn" data-val="*">x</view>
</view>
<view>
<view class="item" bindtap="numBtn" data-val="4">4</view>
<view class="item" bindtap="numBtn" data-val="5">5</view>
<view class="item" bindtap="numBtn" data-val="6">6</view>
<view class="item" bindtap="opBtn" data-val="-">-</view>
</view>
<view>
<view class="item" bindtap="numBtn" data-val="1">1</view>
<view class="item" bindtap="numBtn" data-val="2">2</view>
<view class="item" bindtap="numBtn" data-val="3">3</view>
<view class="item" bindtap="opBtn" data-val="+">+</view>
</view>
<view>
<view class="item tow" bindtap="numBtn" data-val="0">0</view>
<view class="item one" bindtap="dotBtn" data-val=".">.</view>
<view class="item one" bindtap="opBtn" data-val="=">=</view>
</view>
</view>
index.css
page {
display: flex;
flex-direction: column;
height: 100%;
}
.content {
flex: 1;
background-color: #f3f6fe;
position: relative;
}
.content .num {
position: absolute;
font-size: 27pt;
bottom: 5vh;
right: 3vw;
}
.content .operotor {
font-size: 15pt;
position: absolute;
bottom: 1vh;
right: 3vw;
}
.entry {
flex: 1;
font-size: 17pt;
border-top: 1rpx solid #ccc;
}
.entry .item {
flex: 1;
padding: 30rpx 0;
text-align: center;
flex-basis: 25%;
border-left: 1rpx solid #ccc;
border-bottom: 1rpx solid #ccc;
}
.entry > view {
display: flex;
}
.entry > view .tow {
flex: 2;
}
.entry > view .one {
flex: 1;
}
index.js
Page({
data: {
num: "", //
op: "" //
},
result: null,
isClear: false,
numBtn: function(e) {
var num = e.target.dataset.val
//console.log(num) data-val
console.log(this.isClear)
if (this.data.num === "0" || this.isClear) {
this.setData({ num: num })
this.isClear = false
} else {
this.setData({ num: this.data.num + num })
}
},
opBtn: function(e) {
var op = this.data.op
var num = Number(this.data.num)
this.setData({ op: e.target.dataset.val })
if (this.isClear) {
return
}
this.isClear = true
if (this.result === null) {
this.result = num
return
}
if (op === "+") {
this.result = this.result + num
} else if (op === "-") {
this.result = this.result - num
} else if (op === "*") {
this.result = this.result * num
} else if (op === "/") {
this.result = this.result / num
} else if (op === "%") {
this.result = this.result % num
}
this.setData({ num: this.result })
},
dotBtn: function() {
if (this.isClear) {
this.setData({ num: "0." })
this.isClear = false
return
}
if (this.data.num.indexOf(".") >= 0) {
return
}
this.setData({ num: this.data.num + "." })
},
delBtn: function() {
var num = this.data.num.substr(0, this.data.num.length - 1)
this.setData({ num: num === "" ? "0" : num })
},
resetBtn: function() {
this.result = null
this.isClear = false
this.setData({ num: "0", op: "" })
}
})
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
6일차_파이썬으로 계산기 만들어버리기유튜브를 보면서 만든 초초초 간단 계산기 두두등장! 기왕 만드는거 '남들과는 다른 비주얼로 해보자!' 컨셉을 잡았다 그럼 그 색상은? 심지어 다른 색상명에도 구분이 가지 않는 것들도 보였다... 그래서 간단히(?) ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.