本文共 684 字,大约阅读时间需要 2 分钟。
微信小程序中不支持直接操作dom,要实现这种效果,我们需要通过设置data,然后利用数据和界面的双向绑定来实现它。
.service_selection .is_checked{ border: 1px solid #FE0002 ; color: #FE0002 ; background: #fff; } .service_selection .normal{ border: none; color: #333; background: #F0F1EC; }
data: { isChecked: false }
在js文件中实现这个方法,并另他点击后设置isChecked==true。如下:
serviceSelection(){ this.setData({ isChecked:true }) }
重点是这一句代码
{ { isChecked?'is_checked':'normal'}}"
这是一个三目运算符,当isChecked==true时,在class加上is_checked的样式,为flase时使用normal的样式。这一点的实现类似php控制样式类名的语法。
转载地址:http://hqjqi.baihongyu.com/