js里如何根据id来改变style wx:for 循环
发布于 5 年前 作者 guiying05 2354 次浏览 来自 问答

wx:for  循环后的内容,

<view class=‘icon_ground’>

 <view wx:for=’{{page}}’ wx:key=’’>

   <view id=’’ class=‘icon-circle’ style=‘width:{{item.size}}rpx;height:{{item.size}}rpx;background-color:{{item.color}};’></view>

 </view>

</view>

 data: {

   page: 5

 },

例如:怎么更改第三个尺寸大小和样式。

求助,

1 回复

你这种的话,应该是直接从data里来设置

data: {
  page: [
    {
      size: 12
    },
    {
      size: 12
    },
    {
      size: 16
    }
  ]
}

以下划掉

三种方法

1、style="{{index==2?’’:’’}}"

2、class=“class{{index}}”,wxss里用.class2选择器

3、wxss里用.icon-circle:nth-child(3)选择器

回到顶部