實現(xiàn)單選
實現(xiàn)效果:點擊顯示單選狀態(tài),每次僅能點擊一個元素。
實現(xiàn)方式:
wxml:?
<view wx:for="{
{item_list}}" data-info="{
{index}}" class="{
{menu_index===index?'choose':'no_choose'}}" bind:tap="changeColor">{
{item}}</view>
?item_list是單選的元素,class定義了選中和未選中的顯示形式,changeColor更新點擊元素。
?.wxss?
.choose{
color: red;
background-color: white;
font-weight: bold;
}
.no-choose{
color:black
}
定義選中和未選中的顯示樣式。文章來源:http://www.zghlxwxcb.cn/news/detail-823695.html
.js?文章來源地址http://www.zghlxwxcb.cn/news/detail-823695.html
data:{
item_list:['牛肉粉','小吃','加料','飲料']
},
changeColor(e){
this.setData({
到了這里,關(guān)于微信小程序如何自定義單選和多選的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!