微信小程序-1:比较两数的大小

程序来源》微信小程序开发教程(第二章) 主编:黄寿孟、易芳、陶延涛 

ISBN: 9787566720788

程序运行结果:

<!--index.wxml-->

<view class="container">

<text>第一个数字:</text>

<input id="num1" type="number" bindchange="num1change" />

</view>

<view class="container">

  <text>第二个数字:</text>

<input id="num2" type="number" bindchange="num2change" />

</view>

<button bindtap="compare">确定</button>

<text>比较结果:{{result}}</text>

 


// index.js

Page({

  num1:0,

  num2:0,

  num1change:function(e){

    this.num1=Number(e.detail.value)

    console.log("第1个数为:"+this.num1)

  },

  num2change:function(e){

    this.num2=Number(e.detail.value)

    console.log("第2个数为:"+this.num2)

  },

  compare:function(){

    var str="两数相等"

    if(this.num1>this.num2){

      str="第1个数大"

    }else if(this.num1<this.num2){

      str="第2个数大"

    }

    this.setData({

      result:str

    })

  }

})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值