本文为大家分享了微信小程序实现多选功能的具体代码,供大家参考,具体内容如下
代码:
<!--hotblood_gongkao/pages/answer/answer.wxml-->
<!-- content -->
<view class='answer-list'>
<view class='answer-child'>
<text class='answer-title'><text style='margin-right:28rpx;'>{{num + 1}}/{{quesyion.length}}</text>{{question[num][0]}}</text>
<view class='answer-options'>
<view class="options {{selectIndex[0].sureid" data-index='{{idx}}1' data-text='A' bindtap="{{whether">
<image class="dui {{selectIndex[0].sureid" src='../../images/icon-dui.png' />
<text><text style='margin-right:36rpx;'> A </text>{{question[num][1]}}</text>
</view>
<view class="options {{selectIndex[1].sureid" data-index='{{idx}}2' data-text='B' bindtap="{{whether">
<image class="dui {{selectIndex[1].sureid" src='../../images/icon-dui.png' />
<text><text style='margin-right:36rpx;'> B </text>{{question[num][2]}}</text>
</view>
<view class="options {{selectIndex[2].sureid" data-index='{{idx}}3' data-text='C' bindtap="{{whether">
<image class="dui {{selectIndex[2].sureid" src='../../images/icon-dui.png' />
<text><text style='margin-right:36rpx;'> C </text>{{question[num][3]}}</text>
</view>
<view class="options {{selectIndex[3].sureid" data-index='{{idx}}4' data-text='D' bindtap="{{whether">
<image class="dui {{selectIndex[3].sureid" src='../../images/icon-dui.png' />
<text><text style='margin-right:36rpx;'> D </text>{{question[num][4]}}</text>
</view>
</view>
</view>
<view class="answer {{isWan">
<text>正确答案{{question[num][3]}}</text>
</view>
<view class="subBtn {{isque" bindtap='confirm'>
<text>确定</text>
</view>
<view class="subBtn {{isOne" bindtap='next'>
<text>{{con}}</text>
</view>
<view class="subBtn {{iswancheng" bindtap='submit'>
<text>提交答卷</text>
</view>
</view>
CSS:
/* hotblood_gongkao/pages/answer/answer.wxss */
/* title */
.titleImg{
width: 734rpx;
height: 45rpx;
position: fixed;
top: 0;
display: flex;
flex-direction: row;
align-items: center;
left: 50%;
background: #fbfbfb;
margin-left: -367rpx;
z-index: 10;
}
.titleImg image{
height: 35rpx;
width: 100%;
}
/* end */
page{
height: 100%;
width: 100%;
background: #fbfbfb;
}
.isHide{
display: none;
}
.isShow{
display: block;
}
.title{
font-size: 34rpx;
color: #a6a6a6;
margin: 69rpx 0 0 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.answer-list{
}
.answer-child{
width: 672rpx;
margin: 0 auto;
background: #fff;
border-radius: 20rpx;
padding-top:34rpx;
margin-bottom: 20rpx;
margin-top: 72rpx;
box-sizing: border-box;
box-shadow: 0 0 4rpx #dcdcdc;
}
.answer-title{
font-size: 32rpx;
margin: 0 0 0 52rpx;
}
.answer-options{
display: flex;
flex-direction: column;
width: 642rpx;
margin: 32rpx auto 0 auto;
}
.options{
width: 100%;
height: 72rpx;
line-height: 72rpx;
font-size: 32rpx;
padding-left: 30rpx;
box-sizing: border-box;
margin-bottom: 4rpx;
position: relative;
border: 2rpx solid #fff;
}
.dui{
position: absolute;
height: 41rpx;
width: 59rpx;
top:50%;
margin-top: -20rpx;
right: 16rpx;
display: none;
}
.dui2{
display: block!important;
}
.select{
border: 2rpx solid #4ab07e;
box-sizing: border-box;
}
.submit{
height: 120rpx;
width: 100%;
background: #4ab07e;
color: #fff;
font-size: 34rpx;
line-height: 120rpx;
text-align: center;
position: fixed;
left: 0;
bottom: 0;
}
/* 正确答案 */
.answer{
width: 100%;
text-align: center;
color: #ff122f;
font-size: 34rpx;
font-weight: bold;
margin-top: 64rpx;
}
/* end */
/* 下一题 */
.subBtn{
width: 304rpx;
height: 86rpx;
background: #4ab07e;
color: #fff;
font-size: 34rpx;
text-align: center;
line-height: 86rpx;
border-radius: 20rpx;
margin: 190rpx auto 0 auto;
}
js:
// hotblood_gongkao/pages/answer/answer.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
question: [
["今天是个好日子", "halou word", "java", "javascript", 'c#'],
["今天是个好日子", "halou word", "java", "javascript", 'c#'],
], //题库
index: 0, //选择的索引
wrong: [], //错误
border: '',
num: 0,
con: '下一题',
isOne: true,
isWan: false,
iswancheng: false,
isque: false,
whether: false,
correct: [], //正确
duiList: 0, //答对的个数
cuoList: 0, //答错的个数
selectIndex: [{
sureid: false
},
{
sureid: false
},
{
sureid: false
},
{
sureid: false
},
],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.setData({
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
// 提交答卷
submit: function(e) {
console.log(this.data.duiList);
console.log(this.data.cuoList);
var num = this.data.num; //当前题目下标
var question = this.data.question; //题库
var duiList = this.data.duiList; //答对多少题
var cuoList = this.data.cuoList; //答错多少题
//获得题目对象的长度
var arr = Object.keys(question);
var len = arr.length;
if ((num + 1) == len) {
var grade = (100 / len) * duiList;
console.log(grade);
wx.redirectTo({
url: '../chengjiu/chengjiu?grade=' + grade,
})
}
},
// 确认选择
confirm: function() {
var num = this.data.num;
var question = this.data.question; //题库
//获得题目对象的长度
var arr = Object.keys(question);
var len = arr.length;
if ((num + 1) == len) {
this.setData({
iswancheng: true,
isOne: true,
isWan: true,
isque: false
})
} else {
this.setData({
isOne: false,
whether: true,
isque: false,
isWan: true
})
}
},
// 下一题
next: function() {
var num = this.data.num; //当前题目下标
this.setData({
num: num + 1,
isOne: true,
isWan: false,
whether: false,
index: 0
})
},
// 选择答案
selectAnswer: function(e) {
console.log(e);
var index1 = e.currentTarget.dataset.index - 1; //当前点击元素的自定义数据,这个很关键
var selectIndex = this.data.selectIndex; //取到data里的selectIndex
selectIndex[index1].sureid = !selectIndex[index1].sureid; //点击就赋相反的值
console.log(selectIndex[index1])
this.setData({
selectIndex: selectIndex //将已改变属性的json数组更新
})
console.log(this.data.selectIndex.in_array(true))
if (selectIndex.in_array(true) == false) {
this.setData({
isque: false
})
} else {
var question = this.data.question; //题库
var num = this.data.num; //当前题目下标
var text = e.currentTarget.dataset.text; //选择的答案
var duiList = this.data.duiList; //答对多少题
var cuoList = this.data.cuoList; //答错多少题
//获得题目对象的长度
var arr = Object.keys(question);
var len = arr.length;
//当前答题为最后一题
if ((num + 1) == len) {
//判断选择的答案和正确答案是否一致
if (text == question[num][3]) {
duiList = duiList + 1;
this.setData({
duiList: duiList,
isque: true
})
} else {
cuoList = cuoList + 1;
this.setData({
cuoList: cuoList,
isque: true
})
}
} else {
//判断选择的答案和正确答案是否一致
if (text == question[num][3]) {
duiList = duiList + 1;
this.setData({
duiList: duiList,
isque: true
})
} else {
cuoList = cuoList + 1;
this.setData({
cuoList: cuoList,
isque: true
})
}
}
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
this.question();
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})
Array.prototype.in_array = function(element) {
for (var i = 0; i < this.length; i++) {
if (this[i].sureid == element) {
return true;
}
}
return false;
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
微信小程序,多选
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“微信小程序实现多选功能”评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新动态
2025年11月06日
2025年11月06日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]
