zl程序教程

您现在的位置是:首页 >  其他

当前栏目

微信小程序 点击事件 传递参数

事件微信程序 参数 点击 传递
2023-09-11 14:21:10 时间

wxml:

data-参数名="值"

bindtap="函数名"

<view class="buy-button {{cap_select == 100 ? 'zp-active': ''}}" data-cap="100" bindtap="choose_cap">
  <text>100ML \n (2两)</text>
</view>

JS:

choose_cap(res) {
  // 通过 currentTarget 获取传递进来的值
  console.log(res.currentTarget.dataset.cap);
  console.log(res);
},