微信小程序——绑定点击事件

微信小程序出来了那么长时间了,之前一直准备升学和毕业设计(过段时间我要写一写我的毕业设计),最近马上毕业了,终于有时间来研究一下了,先从最简单的点击事件开始吧!

首先我们在test.wxml中加入以下代码:

  
      Hello {{name}}!
      
  

在test.js中加入以下代码:

var helloData = {
  name: 'wechat'
}
Page({
  data: helloData,
  changeName: function (e) {
    this.setData({
      name: 'MENCRE'
    })
  }
})

在test.js中的的data: helloData是对页面中{{name}}的初始化,打开页面时直接将{{name}}替换为'wechat'。

bindtap="changeName"为按钮的点击事件,点击按钮时触发“changeName”事件,然后将name更改为'MENCRE'。

你可能感兴趣的:(小程序,微信小程序入门开发教程)