Home > WeChat Applet > Mini Program Development > How to click and transfer value in WeChat applet

How to click and transfer value in WeChat applet

angryTom
Release: 2020-03-23 12:15:03
Original
3999 people have browsed it

How to click and transfer value in WeChat applet

How to click and pass value in WeChat mini program

How to click and pass value in WeChat mini program:

1. First, in Use data- in wxml to add custom attributes;

2. Then bind the click event through bindtap;

3. Finally, use currentTarget in js to get the passed value.

Recommended learning: Small program development

Code example:

wxml:

data-parameter name="value"

bindtap="function name"

<view class="buy-button {{cap_select == 100 ? &#39;zp-active&#39;: &#39;&#39;}}" data-cap="100" bindtap="choose_cap">
  <text>100ML \n (2两)</text>
</view>
Copy after login

JS:

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

PHP Chinese website, a large number of website construction tutorials , welcome to learn!

The above is the detailed content of How to click and transfer value in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template