微信小程序 bindtap 傳參的實(shí)例代碼
微信小程序 bindtap 傳參 ,代碼如下所示:
//index.wxml
<view bindtap="changeIndex" data-src="我固定參數(shù)">
</view>
//index.js
page({
data:{
},
changeIndex(e){
console.log(e.currentTarget.dataset.src); //我是固定參數(shù)
}
});
可以看出 參數(shù)是通過給標(biāo)簽設(shè)置 data-參數(shù)名=“參數(shù)值” 自定義屬性的方式 來傳遞的 例如想傳遞兩個(gè)參數(shù)
//index.wxml
<view bindtap="changeIndex" data-src1="我固定參數(shù)1" data-src2="我是固定參數(shù)2" >
</view>
//index.js
page({
data:{
},
changeIndex(e){
console.log(e.currentTarget.dataset.src1); //我是固定參數(shù)1
console.log(e.currentTarget.dataset.src2); //我是固定參數(shù)2
}
});
如果需要傳遞動(dòng)態(tài)的參數(shù) 例如遍歷渲染時(shí) 想傳遞 index 給 changeIndex方法
//index.wxml
<view wx:for="{{lists}}" wx:for-index="index" wx:key="index" data-index="{{index}}" >
{{item.title}}
</view>
//index.js
page({
data:{
lists:[{title:'參數(shù)1',id:1},{title:'參數(shù)2',id:2}]
},
changeIndex(e){
console.log(e.currentTarget.dataset.index);
}
})
知識(shí)點(diǎn)補(bǔ)充:
微信小程序:bindtap方法傳參
1、wxml
<view bindtap="pay_again" data-name="{{orderList.jid}}" data-fee="{{orderList.act_fee}}" data-mobile="{{orderList.p_phone}}" data-act="{{orderList.act_name}}" class="operating f_r webkit-box" style="line-height:30px;">
<a href="" class=" rel="external nofollow" pay bg_red">繼續(xù)支付</a>
</view>
2、js
// 再次發(fā)起支付請(qǐng)求,調(diào)用后臺(tái)PHP
pay_again:function(e){
var that = this;
that.setData({
jid: e.currentTarget.dataset.name,
act_name: e.currentTarget.dataset.act,
act_fee: e.currentTarget.dataset.fee,
mobile: e.currentTarget.dataset.mobile
})
console.log('活動(dòng)訂單id = ' + that.data.mobile);
}
總結(jié)
到此這篇關(guān)于微信小程序 bindtap 傳參的實(shí)例代碼的文章就介紹到這了,更多相關(guān)微信小程序 bindtap 傳參內(nèi)容請(qǐng)搜素腳本之家以前的文章或下面相關(guān)文章,希望大家以后多多支持腳本之家!
相關(guān)文章
Typescript的三種運(yùn)行方式(小結(jié))
這篇文章主要介紹了Typescript的三種運(yùn)行方式,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
javascript中日期函數(shù)new Date()的瀏覽器兼容性問題
這篇文章主要介紹了javascript中日期函數(shù)new Date()的瀏覽器兼容性問題,需要的朋友可以參考下2015-09-09
JavaScript ECMA-262-3 深入解析.第三章.this
在這篇文章里,我們將討論跟執(zhí)行上下文直接相關(guān)的更多細(xì)節(jié)。討論的主題就是this關(guān)鍵字2011-09-09
Promise+async+Generator的實(shí)現(xiàn)原理
這篇文章主要介紹了Promise+async+Generator的實(shí)現(xiàn)原理,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09
JavaScript constructor和instanceof,JSOO中的一對(duì)歡喜冤家
現(xiàn)在流行面向?qū)ο?JavaScript當(dāng)然要迎頭趕上. 有說法JavaScript就是徹頭徹尾的OO語言,但我覺得JavaScript實(shí)現(xiàn)面向?qū)ο蟮某绦蜻€是有諸多不便的.2009-05-05
原生js如何實(shí)現(xiàn)call,apply以及bind
這篇文章主要介紹了原生js實(shí)現(xiàn)call,apply以及bind,幫助大家更好的理解和學(xué)習(xí)使用JavaScript,感興趣的朋友可以了解下2021-04-04
layui使用button按鈕 點(diǎn)擊出現(xiàn)彈層 彈層中加載表單的實(shí)例
今天小編就為大家分享一篇layui使用button按鈕 點(diǎn)擊出現(xiàn)彈層 彈層中加載表單的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-09-09
OkHttp踩坑隨筆為何 response.body().string() 只能調(diào)用一次
想必大家都用過或接觸過 OkHttp,我最近在使用 Okhttp 時(shí),就踩到一個(gè)坑,在這兒分享出來,以后大家遇到類似問題時(shí)就可以繞過去2018-01-01

