程序三元运算符点击循环列表中的某⼀项切换颜⾊进⾏
参数携带(原创)
先上效果图
整体思路⼤概是:wx:for循环出你的list  每个list有单独的id  点击事件bindtap ⽤三元运算符判断id是否相等,然后js⾥u_current只要相等就增加⼀个active,参数携带都在e.currentTarget ⾥⾯
wxml代码
仙剑奇侠传3的所有歌曲钢琴谱天空之城<scroll-view class="pup_bottom" scroll-y="true">
<view class='p_content_list'>
<view class="list_all {{ u_current == index ? 'active' : '' }}" wx:for="{{u_items}}" wx:key="{{u_1}}" bindtap="{{ u_radio_checked != index ? 'u_radio_checked':'' }          <span class='list_left'>{{item.nam
e}}</span>
<span class='list_right'>{{}}元</span>宋雨琦的真名
</view>
<view class='bottom_r'> {{u_selected_value}}</view>
</view>
</scroll-view>
wxss 代码
.active{
color:red;
border:1px solid red;
}
js代码
u_items: [{
name: '模特',
money: '1000'
侧田好人},
{
name: '演员',
money: '5550'
},
{
name: '车模',
money: '2220'
},
{
name: '歌⼿',
money: '7770'
},
],
u_radio_checked: 0,
index: 0,
// U选点击事件
u_radio_checked: function (e) {
蒋佳恩事件始末
var that = this;
console.log(e)
this.setData({
u_current: e.currentTarget.id,  //按钮CSS变化
u_selected_value: e._relatedInfo.anchorRelatedText,
})
},
黑蝙蝠中队英文版总结:web端 jq 写多了总是想去进⾏addclass removeclass ,⼩程序暂时没有dom操作所
以⽤三元运算符配合双向数据绑定也能实现这个需求!