注册

微信小程序radio样式能不能自定义?

2020-09-27
导读:小程序的radio样式自定义是可以的,直接用display:none隐藏掉,然后用新标签实现。...
小程序的radio样式不能自定义吗?
微信小程序radio样式能不能自定义?

小程序的radio样式自定义是可以的,直接用display:none隐藏掉,然后用新标签实现。

<radio-group bindchange="radioChange"> 
<label class="ui-radio {{item.checked==true?'active':''}}" wx:for="{{items}}>
                    checked="{{item.checked}}">radio>
                    <text class="text">{{item.name}}text>
                label>
radio-group>
.ui-radio radio,.ui-radio checkbox {
  display: none;
}
.ui-radio .text {
/*设计样式*/
}
.ui-radio.checked .text {
/*设计样式*/
}
Page({
  data: {
    items: [
      {value: 'USA', name: '美国'},
      {value: 'CHN', name: '中国', checked: 'true'},
      {value: 'BRA', name: '巴西'},
      {value: 'JPN', name: '日本'},
      {value: 'ENG', name: '英国'},
      {value: 'FRA', name: '法国'},
    ]
  },
  radioChange: function(e) {
    console.log('radio发生change事件,携带value值为:', e.detail.value)

    var items = this.data.items;
    for (var i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value == e.detail.value
    }

    this.setData({
      items: items
    });
  }
})

把 radio 元素隐藏, 宽度设为 0, 切两张图片或者 svg,用 label 元素的 background 属性自定义 radio.

微信小程序radio样式能不能自定义?

重磅推荐:小程序开店目录

第一部分:小商店是什么

第二部分:如何开通一个小商店

第三部分:如何登录小商店

第四部分:开店任务常见问题

第五部分:小商店可以卖什么

第六部分:HiShop小程序特色功能

第七部分:小程序直播

第八部分:小程序收货/物流

第九部分:小程序怎么结算

第十部分:小程序客服

第十一部分:电商创业

第十二部分:小程序游戏开发