微信小程序开发教程-按钮事件

介绍

下面例子:tap 表示单击,bind 表示绑定 handle 函数,即:单击按钮时,执行 handle 函数

<!-- 点击事件 -->
<button bind:tap="handle">点击</button>
<!-- 简写 bindtap -->
<button bindtap="handle">简写点击</button>

例子

目录结构

wxml文件

在 .wxml 中加上按钮,如下:

<view>
  <button bind:tap="handle">按钮</button>
</view>

js文件

在 .js 中加上事件函数,如下:

handle(e){
  console.log("点击按钮,e",e)
}

执行结果

点击按钮,在控制台中查看打印结果,如下图:


原文出处:/show_1GW3XLdGyPLB.html