小程序属性单项选择

话不多说,先看效果图:


下面直接贴代码:

wxml:

<!-- 选择颜色 -->
< view class= "Choosecolor">
< view class= "colortext">选择颜色 </ view >
< view class= "colorview">
< view class= "{{curIndex==index ?'itemview':'itemviewss'}}" bindtap= "ChooseColor" data-item= "{{item}}" data-index= "{{index}}" wx:for= "{{color}}">{{item.color}} </ view >
</ view >
</ view >
< text >你选的是:{{title}} </ text >


css:

/* 选择颜色 */
.Choosecolor {
width: 94%;
margin: 0 auto;
border-radius: 15 rpx;
padding-bottom: 25 rpx;
background-color: white;
}
.colortext {
width: 100%;
font-size: 32 rpx;
font-family: 微软雅黑;
text-align: center;
padding: 25 rpx 0 0 0;
}
.colorview {
width: 100%;
display: flex;
flex-wrap: wrap;
}
.itemview {
width: 200 rpx;
height: 75 rpx;
margin-left: 25 rpx;
margin-top: 25 rpx;
text-align: center;
line-height: 75 rpx;
font-size: 30 rpx;
font-family: 微软雅黑;
background-color: #dbf5fe;
border: 2 rpx #1bb6ea solid;
border-radius: 10 rpx;
}
.itemviewss {
width: 200 rpx;
height: 75 rpx;
margin-left: 25 rpx;
margin-top: 25 rpx;
text-align: center;
line-height: 75 rpx;
font-size: 28 rpx;
font-family: 微软雅黑;
background-color: white;
border: 2 rpx #efeff4 solid;
border-radius: 10 rpx;
}

js;

Page({

data: {
itemview: false,
color: [
{ color: "红色" },
{ color: "橙色" },
{ color: "黄色" },
]
},

ChooseColor: function (res) {
var that = this
console.log( "你选的是:", res.target.dataset.item.color)
var index = res.target.dataset.index
console.log(index, "index index ")
console.log(that.data.itemview, "that.data.itemview ")

if (that.data.itemview == false) {
that.setData({
itemview: true,
})
} else {
that.setData({
itemview: false
})
}
that.setData({
curIndex: index,
title: res.target.dataset.item.color
})
},

})








  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值