javascript - 小程序如何點(diǎn)擊獲取下標(biāo)
問題描述
<view class='buy-course-box'>
<view class='buy-selects buy-card'> <label wx:for='{{cardName}}' bindtap='setCard'><input type='radio' /><view>{{item.name}}</view> </label> </view> </view>
我想點(diǎn)擊取下標(biāo)但是沒有成功,應(yīng)該怎么做
問題解答
回答1:Carousel:function(event){ var idx=event.target.dataset.index; this.setData({indx:idx }) }
就是這樣,請(qǐng)采納
回答2:data傳參鏈接描述
事件的使用方式在組件中綁定一個(gè)事件處理函數(shù)。如bindtap,當(dāng)用戶點(diǎn)擊該組件的時(shí)候會(huì)在該頁面對(duì)應(yīng)的Page中找到相應(yīng)的事件處理函數(shù)。<view data-hi='WeChat' bindtap='tapName'> Click me! </view>在相應(yīng)的Page定義中寫上相應(yīng)的事件處理函數(shù),參數(shù)是event。Page({ tapName: function(event) { console.log(event) }})可以看到log出來的信息大致如下:{'type':'tap','timeStamp':895,'target': { 'id': 'tapTest', 'dataset': { 'hi':'WeChat' }},'currentTarget': { 'id': 'tapTest', 'dataset': { 'hi':'WeChat' }},'detail': { 'x':53, 'y':14},'touches':[{ 'identifier':0, 'pageX':53, 'pageY':14, 'clientX':53, 'clientY':14}],'changedTouches':[{ 'identifier':0, 'pageX':53, 'pageY':14, 'clientX':53, 'clientY':14}]}回答3:
wx:for-index='index' 應(yīng)該可以通過這種方式直接得到下標(biāo)把
相關(guān)文章:
1. mysql數(shù)據(jù)庫做關(guān)聯(lián)一般用id還是用戶名2. linux運(yùn)維 - python遠(yuǎn)程控制windows如何實(shí)現(xiàn)3. thinkPHP5中獲取數(shù)據(jù)庫數(shù)據(jù)后默認(rèn)選中下拉框的值,傳遞到后臺(tái)消失不見。有圖有代碼,希望有人幫忙4. python小白 關(guān)于類里面的方法獲取變量失敗的問題5. python - 如何對(duì)列表中的列表進(jìn)行頻率統(tǒng)計(jì)?6. javascript - 如何用最快的速度C#或Python開發(fā)一個(gè)桌面應(yīng)用程序來訪問我的網(wǎng)站?7. Python2中code.co_kwonlyargcount的等效寫法8. django - Python error: [Errno 99] Cannot assign requested address9. python小白,關(guān)于函數(shù)問題10. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時(shí)間會(huì)消失是什么情況?
