zoukankan      html  css  js  c++  java
  • 按钮事件--嵌套事件(冒泡)--带参数事件--双向数据绑定

    <!--按钮事件-->
      <button bindtap="buttonTapHandle">点击事件</button>
     buttonTapHandle: function (e) {
        console.log("我点击了")
        //console.dir(e)将一个对象以树状形式打印到控制台
        console.dir(e)
      },
    <!--冒泡事件,嵌套事件,防止两个一块执行-->
      <view bindtap="outerHandle" style="200px; height:200px; background-color:red">
      <!--<view bindtap="innerHandle" style="100px; height:100px; background-color:blue">
        </view>-->
        <view catchtap="innerHandle" style="100px; height:100px; background-color:blue">
        </view>
      </view>
    outerHandle: function(){
        console.log("外部的事件")
      },
      //防止冒泡,将bindtap给为catchtap
      innerHandle: function(){
        console.log("内部的事件")
      },
     <!--事件传参-->
      <button bindtap="tap2Handle" data-name="张三">点击事件</button>
     tap2Handle: function (e){
        console.dir(e.target.dataset.name)
        //console.log(this)//事件处理函数中的this指定的还是页面对象
      },
    <!-- 双向数据绑定 -->
      <view>
        <input value="{{ message2 }}" bindinput="inputHandle" style="border:2px solid #C0C0C0;" />
        <text>{{ message2 }}</text>
      </view>  
    inputHandle: function (e){
        // this.data.message2 = e.detail.value//直接赋值,不能实时改变
        //调用setData方法,实时监听改变
        this.setData({
          message2 : e.detail.value
        })

    index.js

    //index.js
    //获取应用实例
    const app = getApp()
    //将多有的数据和事件写到page方法中
    Page({
      //为页面提供数据的
      //data就是界面和逻辑之间的桥梁
      data:{
        message:"Hello world",
        perssion:{
          name: "zhangsan",
          age: 12
        },
        viewClassname:"hello",
        todos:[
          { name: 'javascript', completed:false },
          { name: 'html', completed: true },
          { name: 'css', completed: false }
        ],
        message2:"",
      },
      buttonTapHandle: function (e) {
        console.log("我点击了")
        //console.dir(e)将一个对象以树状形式打印到控制台
        console.dir(e)
      },
      outerHandle: function(){
        console.log("外部的事件")
      },
      //防止冒泡,将bindtap给为catchtap
      innerHandle: function(){
        console.log("内部的事件")
      },
      tap2Handle: function (e){
        console.dir(e.target.dataset.name)
        //console.log(this)//事件处理函数中的this指定的还是页面对象
      },
      inputHandle: function (e){
        // this.data.message2 = e.detail.value//直接赋值,不能实时改变
        //调用setData方法,实时监听改变
        this.setData({
          message2 : e.detail.value
        })
      }
    })

    index.wxml

    <!--index.wxml-->
    <!-- 基于xml语言,用来定义页面结构单标签也也结束例如image-->
    <view class="container">
      <text>{{message}}</text>
      <text>{{perssion.name}}</text>
      <text>{{perssion.age}}</text>
      <view class=" style1 {{viewClassname}}"></view>
      <!-- mestach语法可以用在以上,不能用于定义标签名和属性名-->
      <!--可以直接使用字面量和简单的逻辑运算符-->
      
      <!--列表渲染-->
      <!--起别名wx:for-item="别名"-->
      <view>
        <view wx:for="{{ todos }}" wx:key="key">
          <text>{{ index }}</text>
          <checkbox checked="{{ item.completed }}"></checkbox>
          <text>{{ item.name }}</text>
        </view> 
      </view>
    
      <!--按钮事件-->
      <button bindtap="buttonTapHandle">点击事件</button>
    
      <!--冒泡事件,嵌套事件,防止两个一块执行-->
      <view bindtap="outerHandle" style="200px; height:200px; background-color:red">
      <!--<view bindtap="innerHandle" style="100px; height:100px; background-color:blue">
        </view>-->
        <view catchtap="innerHandle" style="100px; height:100px; background-color:blue">
        </view>
      </view>
    
       <!--事件传参-->
      <button bindtap="tap2Handle" data-name="张三">点击事件</button>
    
      <!-- 双向数据绑定 -->
      <view>
        <input value="{{ message2 }}" bindinput="inputHandle" style="border:2px solid #C0C0C0;" />
        <text>{{ message2 }}</text>
      </view>  
    </view>

     

  • 相关阅读:
    如何提高Android代码的安全性
    Android数据库安全解决方案,使用SQLCipher进行加解密
    【Android UI设计与开发】第16期:滑动菜单栏(一)
    4种必须知道的Android屏幕自适应解决方案
    android权限大全
    在Windows7下构建Android的开发环境
    Android 悬浮歌词(迷你歌词)效果解读 (转)
    大数据量数据库优化(转)
    使用isInEditMode解决可视化编辑器无法识别自定义控件的问题(转)
    导入开源项目后报:Caused by: java.lang.ClassNotFoundException: Didn't find class
  • 原文地址:https://www.cnblogs.com/fdxjava/p/11547213.html
Copyright © 2011-2022 走看看