微信小程序前端开发试题选择题的选择功能

先贴效果图

在这里插入图片描述

wxml文件
<view>
  	{{exam.a.title}}
</view>

<view class="box">
  	<block wx:for="{{exam.b}}" wx:key="index">
  		<view class="every {{is_yes && is_if == index ? 'right':''}} {{!is_yes && exam.a.key == item.choice  ? 'right':''}} {{!is_yes && is_if == index ? 'error':'' }}" style="pointer-events: {{ban ? 'none':'auto'}}" bindtap="select" data-choice="{{item.choice}}" data-index="{{index}}">{{item.choice}}、{{item.content}}</view>
	</block>
</view>
wxss文件
.box{
  width: 100vw;
}
.every{
  width: 80vw;
  height: 80rpx;
  border: 1px solid #ccc;
  display: flex;
  align-items: center;
  margin: 0 10vw;
  margin-top: 20rpx;
}

.error{
  background-color: red;
  color: #fff;
}

.right{
  background-color: #31c27c;
  color: #fff;
}
js文件内容
Page({
  data: {
    "is_if": 99,
    "is_yes": 99,
    "ban": false,
    "exam": {
      a: {
        "title": "1、下列语句中,显示没有下画线的超链接的语句是(  )",
        "key": 'A'
      },
      b: [{
          "choice": "A",
          "content": "a{text—decoration:none}"
        },
        {
          "choice": "B",
          "content": "a{text—decoration:no underline}"
        },
        {
          "choice": "C",
          "content": "a{decoration:no underline}"
        },
        {
          "choice": "D",
          "content": "a{text—decoration:none}"
        }
      ]
    }
  },
  select(e) {
    let msg = e.target.dataset
    const key = msg.choice == this.data.exam.a.key
    this.setData({
      is_yes: key ? true : false,
      is_if: msg.index,
      ban: true  //选择一次后是否禁止再次选择
    })
  },
})
  • 6
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值