事件绑定

绑定事件

在input标签内使用bindinput关键字,可以绑定input事件

例如:

index.wxml中
<input type="text" bindinput="handInputOne">

index.js中
handInputOne(a){ console.log(a) //若要在控制台使出看到a,则 console.log(a.detail.value) }

  • 若想用户在上面输入,下一行就输出用户输入的(双向绑定),则

    index.wxml中
    <input type="text" bindinput="handInputTwo"> <view>{{num}}</view>
    index.js中
    handInputTwo(b)({ num:b.this.setDatab })

  • 制作一个数字加减按钮(有一个数字,有两个按钮加、减),则

    index.wxml中
    <input type="text" bindinput="handInputThree"> <button bindtap="handletap" data-operation="{{1}}">+</button> <button bindtap="handletap" data-operation="{{-1}}">-</button> <view>{{num1}}</view>

    index.js中
    page({ data:{ num1:3 }, handletap(b){ const operation=b.currentTarget.dataset.operation; this.setData({ num1:this.data.num1+operation }) } })

posted @ 2021-04-27 17:30  imustdoit  阅读(81)  评论(0)    收藏  举报