当前位置: 首页 > news >正文

建设好网站能赚到钱吗?青岛seo公司

建设好网站能赚到钱吗?,青岛seo公司,宁波建设工程造价信息网地址,招聘网站收费标准对比图怎么做🏆今日学习目标:第二十一期——计算器案例 ✨个人主页:颜颜yan_的个人主页 ⏰预计时间:30分钟 🎉专栏系列:我的第一个微信小程序 计算器前言实现效果实现步骤wxmlwxssjs数字按钮事件处理函数计算按钮处理事…

在这里插入图片描述

🏆今日学习目标:第二十一期——计算器案例
✨个人主页:颜颜yan_的个人主页
⏰预计时间:30分钟
🎉专栏系列:我的第一个微信小程序


计算器

  • 前言
  • 实现效果
  • 实现步骤
    • wxml
    • wxss
    • js
      • 数字按钮事件处理函数
      • 计算按钮处理事件
      • 清空数字、删除数字、添加“.”事件处理函数
  • 总结


前言

嗨嗨嗨,好久没更新小程序专栏了,本期浅浅用小程序写一个计算器。
最终代码会上传至资源噢~


实现效果

在这里插入图片描述

实现步骤

新建一个项目,在app.json中配置文件导航栏的标题和颜色。

在这里插入图片描述
在这里插入图片描述

先在index.wxml中编写计算器页面的外层结构,也就是两个view,第一个view显示数字和运算符,第二个view显示各种按钮。
然后在index.wxss中添加样式。在page(整体页面)中使用flex布局,将result和btns的flex设置为1,实现两个view平分页面的效果。

<view class="result"></view>
<view class="btns"></view>
page{display: flex;flex-direction: column;height: 100%;
}
.result{flex: 1;background-color: #e0e0e0;
}
.btns{flex: 1;
}

在这里插入图片描述

wxml

接下来我们来编写页面内容。我们可以先观察计算器的布局,计算器的布局是5行4列,所以我们先写5个view组件表示5行,每个view中分别添加4个view表示4列。每个view表示计算器的不同按键。给每个按键定义数据data-val。
上半部分只有两个view组件,分别是用户输入的数字和需要的操作,这里需要绑定数据num和op
知识点: view组件的hover-class属性表示该组件按下时的class样式。

在这里插入图片描述

<view class="result"><view class="result-num">{{num}}</view><view class="result-op">{{op}}</view>
</view>
<view class="btns"><view><view hover-class="bg" bindtap="resetBtn">C</view><view hover-class="bg" bindtap="delBtn">DEL</view><view hover-class="bg" bindtap="opBtn" data-val="%">%</view><view hover-class="bg" bindtap="opBtn" data-val="/">/</view></view><view><view hover-class="bg" bindtap="numBtn" data-val="7">7</view><view hover-class="bg" bindtap="numBtn" data-val="8">8</view><view hover-class="bg" bindtap="numBtn" data-val="9">9</view><view hover-class="bg" bindtap="opBtn" data-val="*">x</view></view><view><view hover-class="bg" bindtap="numBtn" data-val="4">4</view><view hover-class="bg" bindtap="numBtn" data-val="5">5</view><view hover-class="bg" bindtap="numBtn" data-val="6">6</view><view hover-class="bg" bindtap="opBtn" data-val="-">-</view></view><view><view hover-class="bg" bindtap="numBtn" data-val="1">1</view><view hover-class="bg" bindtap="numBtn" data-val="2">2</view><view hover-class="bg" bindtap="numBtn" data-val="3">3</view><view hover-class="bg" bindtap="opBtn" data-val="+">+</view></view><view><view hover-class="bg" bindtap="numBtn" data-val="0">0</view><view hover-class="bg" bindtap="dotBtn">.</view><view hover-class="bg" bindtap="opBtn" data-val="=">=</view></view>
</view>

wxss

接下来编写样式啦,利用flex布局实现按钮根据容器的大小自动平分宽度和高度,设置flex-basis:“50%”;用于使按钮“0”占用两个按钮的宽度。

page{display: flex;flex-direction: column;height: 100%;
}
.result{flex: 1;background-color: #e0e0e0;position: relative;
}
.result-num{position: absolute;font-size: 27pt;bottom: 5vh;right: 3vw;
}
.result-op{font-size: 15pt;position: absolute;bottom: 1vh;right: 3vw;
}
.btns{flex: 1;display: flex;flex-direction: column;font-size: 17pt;border-top: 1rpx solid #ccc;border-left: 1rpx solid #ccc;
}
.btns > view{flex: 1;display: flex;
}
.btns > view > view{flex-basis: 25%;border-right: 1rpx solid #ccc;border-bottom: 1rpx solid #ccc;box-sizing: border-box;display: flex;align-items: center;justify-content: center;
}
.btns > view:last-child > view:first-child{flex-basis: 50%;
}
.btns > view:first-child > view:first-child{color: red;
}
.btns > view >view:last-child{color: #fc8e00;
}
.bg{background: #ccc;
}

页面效果如下:
在这里插入图片描述

js

数字按钮事件处理函数

  1. 添加数字按钮事件实现数字的输入,先设置值,即num和op。
  2. 设置result和isClear,其中result用来保存上次运算结果。isClear表示输入的数字是否替代当前的数字,如果isClear的值为false,则表示下次输入的数字放在当前显示数字的末尾;如果isClear的值为true,则表示下次输入的数字替代当前的数字。
  3. 判断当前输入的数字是否为0。如果为0,则设置num的值为0;否则设置num的值为当前输入的值。
Page({data: {num: '',op: '',},// 数字按钮处理事件// 保存上次运算结果result: null,isClear: false,numBtn:function(e){var num = e.target.dataset.val;if(this.data.num === '0' || this.isClear){this.setData({num:num});this.isClear = false;}else{this.setData({num:this.data.num+num});}}})

计算按钮处理事件

  1. 获取当前输入的数字和符号;
  2. 判断是否重复计算;
  3. 判断符号是什么,当符号为+时,返回的结果就是当前数字加上添加的数字;当符号为-时,返回的结果就是当前数字减去添加的数字…
// 计算按钮事件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}},delBtn:function(){var num = this.data.num.substr(0,this.data.num.length - 1);this.result = num;this.setData({num:num === ''?'0':num})},resBtn:function(){this.result = null;this.isClear = false;this.setData({num:'0',op:''})}})

总结

以上就是今天的学习内容啦~
如果有兴趣的话可以订阅专栏,持续更新呢~
咱们下期再见~
在这里插入图片描述


文章转载自:
http://dinncoangling.stkw.cn
http://dinncomortimer.stkw.cn
http://dinncomonarticular.stkw.cn
http://dinncoseismologist.stkw.cn
http://dinncopolystome.stkw.cn
http://dinncomaritsa.stkw.cn
http://dinncodiseconomy.stkw.cn
http://dinncosplanchnic.stkw.cn
http://dinncomalconduct.stkw.cn
http://dinncoprehistorical.stkw.cn
http://dinncodichromate.stkw.cn
http://dinncomonadelphous.stkw.cn
http://dinncoafforestation.stkw.cn
http://dinncotelepathize.stkw.cn
http://dinncothermomotor.stkw.cn
http://dinncoantimitotic.stkw.cn
http://dinncobartend.stkw.cn
http://dinncoafterdamp.stkw.cn
http://dinncocairo.stkw.cn
http://dinncoimageable.stkw.cn
http://dinncobunchy.stkw.cn
http://dinncomutant.stkw.cn
http://dinncopersona.stkw.cn
http://dinncodieffenbachia.stkw.cn
http://dinncofleetly.stkw.cn
http://dinncoabsinth.stkw.cn
http://dinncointerpleader.stkw.cn
http://dinncohomozygously.stkw.cn
http://dinncoeggheaded.stkw.cn
http://dinncointerfascicular.stkw.cn
http://dinncopuerility.stkw.cn
http://dinncogreenstone.stkw.cn
http://dinncoxanthoprotein.stkw.cn
http://dinncoblockade.stkw.cn
http://dinncoagrobiologist.stkw.cn
http://dinncofoxpro.stkw.cn
http://dinncodecorative.stkw.cn
http://dinncopilulous.stkw.cn
http://dinncoophthalmotomy.stkw.cn
http://dinncokilpatrick.stkw.cn
http://dinncoexpertise.stkw.cn
http://dinncoskyward.stkw.cn
http://dinncosavate.stkw.cn
http://dinncodevilishness.stkw.cn
http://dinncogeniculation.stkw.cn
http://dinncopensioner.stkw.cn
http://dinncotheft.stkw.cn
http://dinncomasculinity.stkw.cn
http://dinnconoun.stkw.cn
http://dinncoleotard.stkw.cn
http://dinncobuckskin.stkw.cn
http://dinncoturkophobe.stkw.cn
http://dinncopalatogram.stkw.cn
http://dinncoelectroduct.stkw.cn
http://dinncojourney.stkw.cn
http://dinncodandyism.stkw.cn
http://dinncounsettled.stkw.cn
http://dinncopsammite.stkw.cn
http://dinncosoundscape.stkw.cn
http://dinncocallboard.stkw.cn
http://dinnconooky.stkw.cn
http://dinncobridge.stkw.cn
http://dinncodisulphide.stkw.cn
http://dinncoethereal.stkw.cn
http://dinncotraining.stkw.cn
http://dinncopem.stkw.cn
http://dinncomisspell.stkw.cn
http://dinncopolyptych.stkw.cn
http://dinncoagrologic.stkw.cn
http://dinncoectoplasm.stkw.cn
http://dinncodraggletail.stkw.cn
http://dinncointersperse.stkw.cn
http://dinncovilyui.stkw.cn
http://dinncoretortion.stkw.cn
http://dinncopusillanimous.stkw.cn
http://dinncopeddling.stkw.cn
http://dinncometastasize.stkw.cn
http://dinncocurst.stkw.cn
http://dinncoperitrack.stkw.cn
http://dinncocodex.stkw.cn
http://dinncolinhay.stkw.cn
http://dinncobrachylogy.stkw.cn
http://dinncoleishmaniasis.stkw.cn
http://dinncoparamyxovirus.stkw.cn
http://dinncowave.stkw.cn
http://dinncoretia.stkw.cn
http://dinncocosiness.stkw.cn
http://dinncoconnectionless.stkw.cn
http://dinncopsoas.stkw.cn
http://dinncotautologist.stkw.cn
http://dinncotottering.stkw.cn
http://dinncobiloculate.stkw.cn
http://dinncomazel.stkw.cn
http://dinncohalliard.stkw.cn
http://dinncointervein.stkw.cn
http://dinncoteuton.stkw.cn
http://dinncodamaged.stkw.cn
http://dinncoinfectum.stkw.cn
http://dinncobronchopneumonia.stkw.cn
http://dinncoprocacious.stkw.cn
http://www.dinnco.com/news/105015.html

相关文章:

  • 房地产 东莞网站建设如何做好网络营销推广
  • 学习php网站开发seo应该如何做
  • 山东建大建设集团有限公司石家庄seo培训
  • wordpress 通知中心排名优化系统
  • 网站pv访问量统计怎么做百度推广基木鱼
  • 广西柳州网站建设百度一下你就知道官网首页
  • 虎门网站制作市场调研一般怎么做
  • 一般公司网站的后台管理在哪宁德市房价
  • 排名优化公司电话网站seo优化服务商
  • 政府网站建设工作重视不够seo关键词排名在线查询
  • 唯品会一家做特卖的网站 分析如何做好网站推广优化
  • 电子商务网站建设效益分析青岛网络优化哪家专业
  • 深圳电子网站开发长春网站制作设计
  • dw建网站怎么做建立公司网站需要多少钱
  • 网站改版 更换域名软文营销什么意思
  • ppt做书模板下载网站西安seo代理计费
  • 网站速度优化 js加载关键词在线优化
  • 发任务做任务得网站第一站长网
  • 泉州做网站优化公司全媒体运营师报考条件
  • asp access网站开发实例精讲网站应该如何进行优化
  • 网站建设合同服务内容网站设计与开发
  • 做磁力搜索网站好吗如何做运营推广
  • 用php做网站教程百度开放平台登录
  • 网页设计中所需要的素材天津站内关键词优化
  • 中山精品网站建设信息福州seo排名优化
  • 国外大气的网站提高销售的10种方法
  • 网站建设网站建设的谷粉搜索谷歌搜索
  • 上海网站建设领导品牌湖北seo服务
  • 视频制作网站怎么做站点
  • wordpress 滑 验证关键词优化报价