微信小程序 button 修改样式(增加checkbox和radio的样式修改)

wxss:

登录btn的效果需要在手机号码没有输入正确的情况下设置不可用状态。而默认的是绿色。解决方法主要就是在style里直接设置bg-color,而能实现透明度就是设置opacity=0.4,在验证手机号码正确以后在将opacity设置为1,即不透明。

注册的btn 设置了plain 效果,不过border 默认的是黑色,所以要想取得效果的话,就要在style中设置border-color就可以了。(这都是选择器不熟悉的后果啊)


<view>
    <form bindsubmit="sumit">
        <input bindinput="phone"maxlength="11" type="number" class="marginview" name="phone" placeholder="手机号"/>
        <input bindinput="password" maxlength="8" password class="marginview"name="passworld" placeholder="密码"/>
        <button style="opacity: {{opacity}};color: white; background-color: #ff8719;" disabled="{{disabled}}" loading="{{loginLoading}}"    class="marginview"form-type="submit">登录</button>
    </form>
        <button bindtap="gotoRegist" plain style="color: #ff8719; border-color: #ff8719;"  class="marginview">注册</button>
        <navigator open-type="redirect" hover-class="none" class="marginview textview" url="forgetpw/forgetpw">忘记密码</navigator>
</view>

js: 在sumit里请求服务器,返回成功,则提示登录成功。

//判断是否是手机号码的方法
function IsTel(s){ 
  if(s!=null) {
    var length = s.length;  
    if(length == 11 && /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1})|)+\d{8})$/.test(s) )  
    {  
        return true;  
    }else{  
        return false;  
    }  
  }
}  
 
Page({
  data:{
    disabled:true,  //是否可用
    opacity:0.4,    //设置透明度
  },
//跳转注册页面
  gotoRegist:function(){
     wx.redirectTo({url: '../../pages/login/regist/regist'})
},
//手机的输入框
  phone:function(e){
    var that = this
    //console.log(e.detail.value)
    var isTel = IsTel(e.detail.value)
    //console.log(isTel)
    if(isTel){
      that.setData({
        disabled:false,
        opacity:1 
      })
    }else{
      that.setData({
        disabled:true,
        opacity:0.4
      })
    } 
},
//提交按钮确认
  sumit:function(e){
    console.log(e.detail.value)
    if(e.detail.value.passworld.length==0){
      wx.showModal({
      title: '密码不得为空',
      showCancel:false
    })
  }else{
    //提交
    wx.request({
      url: 'https://URL',
      data: e.detail.value,
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(res){
        // success
        if(res.data==1){  //请求成功返回码
        wx.showToast({
          title: '登陆成功',
          icon: 'success',
          duration: 2000
        })
      }
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  }
},
})

当然,以上效果有很多方式能实现。

附:以下是checkbox 和redio 修改原生样式:

checkbox .wx-checkbox-input{
    border-radius:50%;
    width:20px;height:20px;
}
checkbox .wx-checkbox-input.wx-checkbox-input-checked{
    border-color:red !important;
    background:rebeccapurple !important;
}
checkbox .wx-checkbox-input.wx-checkbox-input-checked::before{
    border-radius:50%;
    width:20px;
    height:20px;
    line-height:20px;
    text-align:center;
    font-size:15px;
    color:#fff;
    background:transparent;
    transform:translate(-50%, -50%) scale(1);
    -webkit-transform:translate(-50%, -50%) scale(1);
}
radio .wx-radio-input{
    border-radius:50%;
    width:20px;height:20px;
}
radio .wx-radio-input.wx-radio-input-checked{
    border-color:coral !important;
    background:aqua !important;
}
radio .wx-radio-input.wx-radio-input-checked::before{
    border-radius:50%;
    width:20px;
    height:20px;
    line-height:20px;
    text-align:center;
    font-size:15px;
    color:#fff;
    background:transparent;
    transform:translate(-50%, -50%) scale(1);
    -webkit-transform:translate(-50%, -50%) scale(1);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值