• 小程序for循环中通过index实现单个点击事件


    <!--xml-->
    <view class='content3-list' wx:for="{{listItems}}" >
    <view class='list-left'>
    <image id="{{index}}" bindtap='clickRight' src= '{{item.rightImage}}' />
    <text class='list-left-wd'>{{item.word}}</text>
    <text class='list-left-exp'>{{item.explain}}</text>
    </view>
    <view class='list-right'>
    <image src="../../images/del.png" />
    </view>
    </view>
     
    <!--js-->
    Page({
    // 页面的初始数据
    data: {
    listItems: [
    {
    "rightImage": "/images/right.png",
    "word": "book",
    "explain": "书;卷;课本;账簿"
    }, {
    "rightImage": "/images/right.png",
    "word": "book",
    "explain": "书;卷;课本;账簿"
    }, {
    "rightImage": "/images/right.png",
    "word": "book",
    "explain": "书;卷;课本;账簿"
    }, {
    "rightImage": "/images/right.png",
    "word": "book",
    "explain": "书;卷;课本;账簿"
    }, {
    "rightImage": "/images/right.png",
    "word": "book",
    "explain": "书;卷;课本;账簿"
    }, {
    "rightImage": "/images/right.png",
    "word": "book",
    "explain": "书;卷;课本;账簿"
    }, {
    "rightImage": "/images/right.png",
    "word": "book",
    "explain": "书;卷;课本;账簿"
    }, {
    "rightImage": "/images/right.png",
    "word": "book",
    "explain": "书;卷;课本;账簿"
    }, {
    "rightImage": "/images/right.png",
    "word": "book",
    "explain": "书;卷;课本;账簿"
    }, {
    "rightImage": "/images/right.png",
    "word": "book",
    "explain": "书;卷;课本;账簿"
    }, {
    "rightImage": "/images/right.png",
    "word": "book",
    "explain": "书;卷;课本;账簿"
    }
    ]
    },
    clickRight: function (e) {
    var idx = parseInt(e.currentTarget.id);
    var img = this.data.listItems;
    if ("/images/right.png" == img[idx].rightImage) {
    img[idx].rightImage = "/images/right1.png";
    } else {
    img[idx].rightImage = "/images/right.png";
    }
    }
    })


  • 相关阅读:
    设计模式学习笔记一
    linux学习记录(一)
    eclipse插件集合
    什么叫反向代理?
    shiro学习四
    shiro学习三
    shiro学习二
    第二次作业
    第一次作业
    自我介绍
  • 原文地址:https://www.cnblogs.com/joyer-lee/p/8117916.html
Copyright © 2020-2023  润新知