微信小程序用户协议须知隐私单选checkbox选中状态判断


HTML

 <view  class="term">
       <checkbox-group bindchange="checkboxChange"> 
            <checkbox value="{{myVal}}" checked="{{is_agree}}"/>
            我已阅读并<text class="fr1" bindtap="showModal1" >同意点餐说明</text>
      </checkbox-group>
  </view>

wxss

.term{
  margin-top: 30rpx;
  padding-bottom: 30rpx;
  line-height: 30rpx;
  font-size: 28rpx;
  font-weight: 700;
  text-align: center;
  color: #999999;
  display: flex;
  justify-content: center;
  white-space: nowrap;  /* 不允许换行 */
}
checkbox-group {
  width: 36rpx;
  height: 36rpx;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
}
checkbox {
  width: 240rpx;
  height: 90rpx;
}
/*checkbox 选项框大小  */
checkbox .wx-checkbox-input {
  width: 50rpx;
  height: 50rpx;
}
/*checkbox选中后样式  */
checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  background: #FF525C;
}
/*checkbox选中后图标样式  */
checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
  width: 28rpx;
  height: 28rpx;
  line-height: 28rpx;
  text-align: center;
  font-size: 22rpx;
  color: #fff;
  background: transparent;
  transform: translate(-50%, -50%) scale(1);
  -webkit-transform: translate(-50%, -50%) scale(1);
}

在html里给 checkbox-group  加上一个点击事件bindchange="checkboxChange"在点击checkbox里就可以取到上面的值,并用值来判断是否选中

 
 
    data:{
    is_agree: '',//判断我已阅读并同意是否为选中状态
      myVal:'N',
  }






checkboxChange(e){
    监听checkbox点击事件 console.log(e,
"点击了外层")

  if(e.detail.value.length == 0){ 当用户点击了取消了checkbox,e.detail.value值就为undefined就为0 console.log(e.detail.value.length) this.setData({ //并把is_agree设置为空就不会选中 is_agree:'',   myVal:'N', }) }else{ //当用户点击了checkbox确定了,值为1 console.log(e.detail.value.length) this.setData({ is_agree:'Y', myVal:'Y', }) // this.confirmOrder() } },

然后就可以根据myVal进行判断了


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM