小程序模板網(wǎng)

微信小程序?qū)崿F(xiàn)類似JQuery siblings()的方法

發(fā)布時間:2018-05-03 15:23 所屬欄目:小程序開發(fā)教程

想要實現(xiàn)的效果:

1、點擊數(shù)字時背景為紅色,字體為白色

2、點擊1或2時,對應(yīng)下面的灰點消失,再次點擊其他數(shù)字時灰點顯示

wxml:


<block wx:for="{{weekDay}}" wx:key="item.index">
          <view data-key="{{index}}" bindtap='select_d' class="day_list {{d_state==index?'red_day':''}}">
            <text>{{item.day_n}}</text>
            <text class='{{item.dian_class}} {{item.state==0?"dian_none":"dian_block"}}'></text>
          </view>
</block>

wxss:


.dian_none{
  display: none!important;
}
.dian_block{
  display: block!important;
}
.red_day{
  background-color: #e33c3c;
  color: #ffffff; 
}
.dian_d{
  width: 9rpx;
  height: 9rpx;
  background-color: #d8d8d8;
  border-radius: 50%;
  display: block;
}

js:


data: {
    date_week:["日","一","二","三","四","五","六"],
    weekDay:[
      {
        day_n:"26",
        dian_class:""
      }, {
        day_n: "27",
        dian_class: ""
      },{
        day_n: "28",
        dian_class: ""
      }, {
        day_n: "29",
        dian_class: ""
      }, {
        day_n: "30",
        dian_class: ""
      }, {
        day_n: "1",
        dian_class: "dian_d",
        state:1
      }, {
        day_n: "2",
        dian_class: "dian_d",
        state:1
      }
   ],
   d_state:"0",
},
select_d:function(e){
    var array = this.data.weekDay;
    var index=e.currentTarget.dataset.key;
    if (array[index].dian_class =="dian_d"){
      for (var i = 0; i < array.length; i++) {
        if (array[i].dian_class == "dian_d") {
          array[i].state = 1;
        }
      }
      array[index].state = 0;
    } else if (array[index].dian_class ==""){
      for (var i = 0; i < array.length; i++){
        if(array[i].dian_class=="dian_d"){
          array[i].state = 1;
        }
      } 
    }
    this.setData({
      d_state:e.currentTarget.dataset.key,
      weekDay:this.data.weekDay
    });
  } 


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://22321a.com/wxmini/doc/course/24194.html 復(fù)制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢:800182392 點擊咨詢
QQ在線咨詢