学无先后,达者为师

网站首页 前端文档 正文

微信小程序比较两个数大小的实现方法_javascript技巧

作者:底层的渣渣   更新时间: 2022-05-26 前端文档

效果图

wxml代码



    请输入第一个数字:
    


    请输入第二个数字:
    



    比较结果为:{{result}}

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

总结

原文链接:https://blog.csdn.net/weixin_52060922/article/details/121669157

栏目分类
最近更新