欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序 bindtap 傳參的實例代碼

 更新時間:2020年02月21日 16:55:06   作者:皮的狠  
這篇文章主要介紹了微信小程序 bindtap 傳參的實例代碼,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下

微信小程序 bindtap 傳參 ,代碼如下所示:

//index.wxml
<view bindtap="changeIndex" data-src="我固定參數(shù)">
</view>
//index.js
page({
 data:{
 },
 changeIndex(e){
 console.log(e.currentTarget.dataset.src); //我是固定參數(shù)
 }
});

可以看出 參數(shù)是通過給標簽設置 data-參數(shù)名=“參數(shù)值” 自定義屬性的方式 來傳遞的 例如想傳遞兩個參數(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
 }
});

如果需要傳遞動態(tài)的參數(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);
 }
})

知識點補充:

微信小程序: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ā)起支付請求,調(diào)用后臺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('活動訂單id = ' + that.data.mobile);
 }

總結(jié)

到此這篇關于微信小程序 bindtap 傳參的實例代碼的文章就介紹到這了,更多相關微信小程序 bindtap 傳參內(nèi)容請搜素腳本之家以前的文章或下面相關文章,希望大家以后多多支持腳本之家!

相關文章

最新評論