微信小程序比较数大小

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

微信小程序比较数大小

底层的渣渣   2022-05-28 我要评论

效果图

wxml代码

<!--index.wxml-->
<view class="demo-box">
    <text class="title">请输入第一个数字:</text>
    <input type="number" bindchange='num1change'/>
</view>
<view class="demo-box">
    <text class="title">请输入第二个数字:</text>
    <input type="number" bindchange='num2change'/>
</view>
<button bindtap='compare'>比较大小</button>
<view class="demo-box">
    <text class="title">比较结果为:{{result}}</text>
</view>

wxss代码

/**index.wxss**/
.demo-box{
    margin: 50rpx;
}
input{
    width: 600rpx;
    margin-top: 20rpx;
    border-bottom: 4rpx solid #cccc;
}
button{
    margin: 50rpx;
}
button{
    color: aliceblue;
    background-color: #369;
    letter-spacing: 12rpx;
}

index.js代码

Page({
  data: { 
      result:''
       },  
    num1:0,//保存一个数字 
    num2:0,  
    num1change:function(e){           
     this.num1 = Number(e.detail.value)   
     console.log("第一个数为:"+this.num1) 
     },  
     num2change:function(e){   
     this.num2 = Number(e.detail.value)    
     console.log("第二个数为"+this.num2)
     },  
     compare:function(e){  
       var str='俩数相等'  
       if(this.num1 > this.num2){  
       str = '第一个数大大大大'   
        }else if (this.num1<this.num2){
          str = '第二个数大大大'
        }    
        this.setData({result:str})  
        },
        })

总结

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们