小程序之用户事件

1. 事件:一种用户的行为,一种通讯方式

2. 事件类别:点击事件(tap),长按事件(long tap) ,触摸事件(touchstart,touchend,touchmove,touchcancel),其他(submit,input)

3.事件绑定:bind绑定(包括父域内容),catch绑定(不包括父域)

4.事件对象:类型(type),时间戳(timeStamp),事件源组件(target),当前组件(currentTarget),触摸点数(touches)

currentTarget: 发生事件的主件,而target为事件发生源


//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    motto: 'Hello World',
    userInfo: {}
  },
  //事件处理函数
   view1click: function(event){
    console.log("view1click")
    console.log(event)
  },
   view2click: function(){
 console.log("view2click")
  },
   view3click: function(event){
 console.log("view3click")
 console.log(event)
  },
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
  }
})
index.wxml:
<view class="view1" bindtap="view1click" id="view1" data-title="新闻标题" data-id="100">
  view 11
      <view class="view2" bindtap="view2click" id="view2">
      view 22
            <view class="view3" bindtap="view3click" id="view3">
            view 33

            </view>
      </view>
</view>

index.wxss:
.view1{
  height: 500rpx;
  width: 100%;
  background-color: rebeccapurple;
}

.view2{
  height: 400rpx;
  width: 80%;
  background-color: red;
}

.view3{
  height: 300rpx;
  width: 60%;
  background-color: saddlebrown;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值