微信小程序案例——成绩优良判断+温度单位转换笔记+计算三角形面积和周长

以下是.wxml文件

<input type="text" name="" id=""  bindinput="inputHandle" />
<view>
  成绩等级:
  <text wx:if="{{sorce>100||sorce<0}}">输入有误</text>
  <text wx:elif="{{sorce == ''}}">请输入分数</text>
  <text wx:elif="{{sorce>=90 && sorce<=100}}">优秀</text>
  <text wx:elif="{{sorce>=80 && sorce<90 }}">良好</text>
  <text wx:elif="{{ sorce>=70 && sorce<80}}">中等</text>
  <text wx:elif="{{ sorce>=60 && sorce<70}}">及格</text>
  <text wx:else>不及格</text>
</view>
<view>
  摄氏温度转化华氏温度
  <input type="text" bindinput="temperatureHandle"/>
  <text>华氏温度:{{temperature}}</text>
</view>

以下是.wxss文件

input{
  width: 700rpx;
  height: 40px;
  border: 1px solid #ccc;
  border-radius: 5px;
  margin: 20rpx 25rpx;
}

以下是主要的.json文件

data: {
    sorce:'',
    temperature:''
  },
  inputHandle(e){
    this.setData({
      sorce:e.detail.value
    })
  },
  temperatureHandle(e){
    this.setData({
      temperature:(9/5)*Number(e.detail.value)+32
    })
  },

 以下是.wxml代码


<view class="number-container">
  <form bindsubmit="formSubmit">
    <input type="text" name="a" id="" placeholder="请输入三角形的边长1" value="{{a}}"/>
    <input type="text" name="b" id="" placeholder="请输入三角形的边长2" value="{{b}}"/>
    <input type="text" name="c" id="" placeholder="请输入三角形的边长3" value="{{c}}"/>
    <button type="primary"  formType="submit">计算</button>
  </form>
<view>
  三角形的周长:{{zc}}
</view>
<view>
  三角形的面积:{{mj}}
</view>
</view>

以下是.wxss代码

.number-container{
  padding: 20px;
}
input{
  height: 35px;
  border: 1px solid #ccc;
  margin-bottom: 20px;
  padding-left:5px ;
}

以下是主要的.js代码

data: {
    zc: '',
    mj: '',
    a: '',
    b: '',
    c: ''

  },
  formSubmit(e) {
    let n1 = e.detail.value.a * 1;
    let n2 = e.detail.value.b * 1;
    let n3 = e.detail.value.c * 1;
    if (n1 + n2 <= n3 || n1 + n3 <= n2 || n2 + n3 <= n1) {
      wx.showToast({
        title: '三角形两边之和小于第三边!',
        icon:"none",
        duration: 1000
      })
      
      
    }
    else{
      let p=(n1+n2+n3)/2
      let s= Math.sqrt(p*(p-n1)*(p-n2)*(p-n3))
      this.setData({
        a:n1,
        b:n2,
        c:n3,
        zc:n1+n2+n3,
        mj:s
      })
    }
  },
  setNull(){
    this.setData({
      a:"",
      b:"",
      c:"",
      zc:"",
      mj:""
    })
  },

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值