In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you the relevant knowledge about how WeChat Mini Programs realizes a simple calculator. the content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article, let's take a look at it.
Run screenshot
Calculators do not require a beautiful interface, just a combination of view and button controls, so you don't need to spend a lot of effort on the interface. The important thing is the logic layer, the reason why I chose the calculator as the first project, because the logic of the calculator can be simple and complex, can fully adapt to the novice's mastery of Mini Program.
Main code
Js:
Page ({data: {result: "0", id1: "clear", id2: "back", id3: "time", id4: "div", id5: "mul", id6: "sub", id7: "add", id8: "dot", id9: "eql", id10: "num_0", id11: "num_1", id12: "num_2", id13: "num_3", id14: "num_4", id15: "num_5" Id16: "num_6", id17: "num_7", id18: "num_8", id19: "num_9", buttonDot:false, is_time:false}, clickButton: function (e) {console.log (e) Var buttonVal = e.target.id; var res= this.data.result; if (this.data.is_time==true) {res=0} var newbuttonDot=this.data.buttonDot; var sign; if (buttonVal > = "num_0" & & buttonVal 1) {res=res.substr;} else {res= "0" } else if (buttonVal = = "div" | | buttonVal = = "mul" | | buttonVal = = "sub" | | buttonVal = = "add") {if (res.length) {} else {res=JSON.stringify (res)} var is_sign=res.substr (res.length-1,res.length) if (is_sign== "+" | | is_sign== "-" | | is_sign== "×" | is_sign== "/") {res=res.substr (0) Res.length-1) } switch (buttonVal) {case "div": sign= "/"; break; case "mul": sign= "×"; break; case "sub": sign= "-"; break; case "add": sign= "+"; break;} if (! isNaN (res.length)) {res.length-1; res=res+sign } this.setData ({is_time:false, result: res, buttonDot:newbuttonDot,});}, equal: function (e) {var str=this.data.result; var item= ""; var strArray = []; var temp=0; for (var item0 var temp=0; for I = "0" & & s
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.