wxml文件
<view class='star_container'>
<image class='star_icon' bindtap='starClick' id='1' src="{{curStarIndex<1?'../../images/star_gray.png':'../../images/star_light.png'}}"></image>
<image class='star_icon' bindtap='starClick' id='2' src="{{curStarIndex<2?'../../images/star_gray.png':'../../images/star_light.png'}}"></image>
<image class='star_icon' bindtap='starClick' id='3' src="{{curStarIndex<3?'../../images/star_gray.png':'../../images/star_light.png'}}"></image>
<image class='star_icon' bindtap='starClick' id='4' src="{{curStarIndex<4?'../../images/star_gray.png':'../../images/star_light.png'}}"></image>
<image class='star_icon' bindtap='starClick' id='5' src="{{curStarIndex<5?'../../images/star_gray.png':'../../images/star_light.png'}}"></image>
</view>
js文件
starClick: function (e) {
var index = parseInt(e.currentTarget.id);
this.setData({
curStarIndex: index,
});
}
效果如图所示