微信小程序怎樣點(diǎn)擊傳值
微信小程序點(diǎn)擊傳值的方法:
1、首先在wxml中使用data-來(lái)添加自定義屬性;
2、然后通過(guò)bindtap來(lái)綁定點(diǎn)擊事件;
3、最后在js中用currentTarget來(lái)獲取傳遞的值即可。
推薦學(xué)習(xí):小程序開(kāi)發(fā)
代碼示例:
wxml:
data-參數(shù)名="值"
bindtap="函數(shù)名"
<view class="buy-button {{cap_select == 100 ? 'zp-active': ''}}" data-cap="100" bindtap="choose_cap"> <text>100ML n (2兩)</text> </view>
JS:
choose_cap(e) { // 通過(guò) currentTarget 獲取傳遞進(jìn)來(lái)的值 console.log(e.currentTarget.dataset.cap); console.log(e); },
PHP中文網(wǎng),大量網(wǎng)站建設(shè)教程,歡迎學(xué)習(xí)!