最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
小程序实现选择题选择效果
时间:2022-06-25 15:29:38 编辑:袖梨 来源:一聚教程网
本文实例为大家分享了小程序实现选择题的显示方法,供大家参考,具体内容如下
下面是三张效果图:初始图,选项正确图,选项错误图。
wxml代码:
a b c d
js代码:
Page({ /** * 页面的初始数据 */ data: { view1: 'selection1', view2: 'selection1', view3: 'selection1', view4: 'selection1', // 默认答案为2,后台会给的 key: 2, // 选项是否被点击 isSelect: false }, view1Click: function(e) { var select = e.target.id // 选项没被选择时将执行 if (!this.data.isSelect) { // 将选项设置为“已被选择” this.setData({ isSelect: true }) // 注意!此处必须是'=='而不是'=' if (select == this.data.key) { this.setData({ view1: 'selection2' }) } else { this.setData({ view1: 'selection3' }) // 将正确选项显示出来 this.showAnswer(this.data.key) } } }, view2Click: function(e) { var select = e.target.id // 选项没被选择时将执行 if (!this.data.isSelect) { this.setData({ isSelect: true }) // 注意!此处必须是'=='而不是'=' if (select == this.data.key) { this.setData({ view2: 'selection2' }) } else { this.setData({ view2: 'selection3' }) // 将正确选项显示出来 this.showAnswer(this.data.key) } } }, view3Click: function(e) { var select = e.target.id // 选项没被选择时将执行 if (!this.data.isSelect) { this.setData({ isSelect: true }) // 注意!此处必须是'=='而不是'=' if (select == this.data.key) { this.setData({ view3: 'selection2' }) } else { this.setData({ view3: 'selection3' }) // 将正确选项显示出来 this.showAnswer(this.data.key) } } }, view4Click: function(e) { var select = e.target.id // 选项没被选择时将执行 if (!this.data.isSelect) { this.setData({ isSelect: true }) // 注意!此处必须是'=='而不是'=' if (select == this.data.key) { this.setData({ view4: 'selection2' }) } else { this.setData({ view4: 'selection3' }) // 将正确选项显示出来 this.showAnswer(this.data.key) } } }, showAnswer: function(key) { // 通过swith语句判断正确答案,从而显示正确选项 switch (key) { case 1: this.setData({ view1: 'selection2' }) break; case 2: this.setData({ view2: 'selection2' }) break; case 3: this.setData({ view3: 'selection2' }) break; default: this.setData({ view4: 'selection2' }) } } })
wxss代码:
css;">.selection1{ width: 400rpx; height: 150rpx; background-color: grey; display: flex; flex-direction: column; justify-content: space-around; align-items: center; } .selection2{ width: 400rpx; height: 150rpx; background-color: blue; display: flex; flex-direction: column; justify-content: space-around; align-items: center; } .selection3{ width: 400rpx; height: 150rpx; background-color: red; display: flex; flex-direction: column; justify-content: space-around; align-items: center; } .selection{ width: 750rpx; height: 800rpx; display: flex; flex-direction: column; justify-content: space-around; align-items: center; }
相关文章
- 《崩坏:星穹铁道》缇宝最强光锥搭配推荐一览 02-20
- 《仙剑世界》潮起介绍 02-20
- 《崩坏:星穹铁道》如果时间是一朵花突破材料汇总 02-20
- 雨水节气的到来,标志着哪个季节的开始 02-20
- 《龙族:卡塞尔之门》活动日历查看位置 02-20
- 《仙剑世界》卡池抽取攻略 02-20