微信小程序实现五星评价
更新时间:2022年08月28日 10:03:14 作者:花笙_
这篇文章主要为大家详细介绍了微信小程序实现五星评价,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了微信小程序实现五星评价的具体代码,供大家参考,具体内容如下
首先准备两张图片,在阿里巴巴矢量图标库中随便下两个颜色不一样的星星

效果如下

wxml
循环五次图片,添加点击事件
<view class="card_start flex">
<span style="font-size: 28rpx;">服务评价</span>
<image class="imagecls" wx:for="{{5}}" wx:key="index" data-name="technicianAssessStar" data-item="{{item}}"
src="{{item-technicianAssessStar+1>0?'/image/self_img/start-noColor.png':'/image/self_img/start-color.png'}}"
bindtap="start_technician"></image>
<span class="ft-size-28 titleRight">{{technician_content}}</span>
</view>默认五颗星(超赞)
js
data:{
technicianAssessStar: 5, // 服务技师评价,默认五颗星
technician_content:'超赞',
}
// 服务评价 技师
start_technician: function (e) {
var technicianAssessStar = e.currentTarget.dataset.item + 1;
var variable = e.currentTarget.dataset.name;
console.log(technicianAssessStar, e)
console.log(variable)
if (variable === "technicianAssessStar")
if (technicianAssessStar === 1) {
this.setData({
technician_content: '很差',
})
} else if (technicianAssessStar === 2) {
this.setData({
technician_content: '差',
})
} else if (technicianAssessStar === 3) {
this.setData({
technician_content: '一般',
})
} else if (technicianAssessStar === 4) {
this.setData({
technician_content: '赞',
})
} else if (technicianAssessStar === 5) {
this.setData({
technician_content: '超赞',
})
}
this.setData({
technicianAssessStar: technicianAssessStar,
})
},打印的数据

wxss
.flex {
display: flex;
}
.card_start {
margin-top: 32rpx;
}
.imagecls {
height: 45rpx;
width: 45rpx;
padding: 0 20rpx;
}
.ft-size-28 {
font-size: 28rpx;
}
.titleRight {
color: rgba(0, 0, 0, 0.25)
}以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
js中的eval()函数把含有转义字符的字符串转换成Object对象的方法
下面小编就为大家带来一篇js中的eval()函数把含有转义字符的字符串转换成Object对象的方法。小编觉的挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2016-12-12
javascript实现点击按钮弹出一个可关闭层窗口同时网页背景变灰的方法
这篇文章主要介绍了javascript实现点击按钮弹出一个可关闭层窗口同时网页背景变灰的方法,涉及javascript鼠标事件及页面元素样式操作的相关技巧,需要的朋友可以参考下2015-05-05
深入理解JavaScript系列(15) 函数(Functions)
本章节我们要着重介绍的是一个非常常见的ECMAScript对象——函数(function),我们将详细讲解一下各种类型的函数是如何影响上下文的变量对象以及每个函数的作用域链都包含什么,以及回答诸如像下面这样的问题:下面声明的函数有什么区别么2012-04-04


最新评论