事件类别:
tap:点击事件;
longtap:长按事件;
touchstart:触摸开始;
touchend:触摸结束;
touchcansce:取消触摸;
事件绑定:
bind绑定;
catch绑定;(能阻止事件冒泡)
例如:绑定点击事件 bindtap
page.wxml 文件
<button bindtap="btnclick"></button>
page.js 文件
//获取应用实例
const app = getApp()
Page({
data: {
text: "你好",
onOff: false
},
btnclick:function(){
console.log('123');
var onOff = this.data.onOff;
this.setData({
text:"hello",onOff:!onOff});
}
})
事件详解:(类型 type ; 时间戳 timeStamp;事件源组件 target ; 当前事件 currentTarget ; 触摸点数 touches)
扫描二维码关注公众号,回复:
11945548 查看本文章
调用项目下的其他事件及调用app.js里面的事件:
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
text: '按钮',
},
btnclick:function(){
var that = this;
console.log('不错');
that.btnchange(); //调用项目的其他事件
app.clickBtn(); //调用app.js里面的事件
},
btnchange:function(){
console.log('yes');
}
})