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進行判斷了
