小程序实战三之微信组件事件及函数传参

项目地址

表单
input表单
<view class='menu-group'>
  <navigator class='menu-item arrow'>
    <text>表单</text>
  </navigator>
  <navigator class='menu-item'>
    <input type='text' placeholder='text'></input>
  </navigator>
  <navigator class='menu-item'>
    <input type='text' password placeholder='password'></input>
  </navigator>
  <navigator class='menu-item'>
    <input type='digit' placeholder='digit'></input>
  </navigator>
  <navigator class='menu-item'>
    <input type='idcard' placeholder='idcard'></input>
  </navigator>
</view>
<view class='divider'></view>
其他表单
<view class='menu-group'>
  <navigator class='menu-item arrow'>
    <text>其他表单</text>
  </navigator>
  <navigator class='menu-item'>
    <checkbox-group bindchange='cbChanged' data-aa='222'>
      <checkbox color='#f60' value='son' checked></checkbox> 呵呵
      <checkbox color='#f60' value='mom'></checkbox> 妈妈
      <checkbox color='#f60' value='dad'></checkbox>爸爸
    </checkbox-group>
  </navigator>
  <navigator class='menu-item'>
    <radio-group bindchange='rbChanged' data-index='1'>
      <radio color='#f60' value='apple'>苹果</radio>
      <radio color='#f60' value='pear'>梨</radio>
    </radio-group>
  </navigator>
  <navigator class='menu-item arrow'>
    <text>你好</text>
  </navigator>
</view>

表单绑定事件和传参

cbChanged(e){
    console.log(e.detail.value + " : " + e.target.dataset.aa)
},
rbChanged(e){
    console.log(e.detail.value + " : " + e.target.dataset.index)
}
wxs 微信页面的脚本程序
<!-- 微信脚本,提供给当前页面逻辑计算的方法 -->
<wxs module='obj'> //module是必要属性

  var inSum = function(a,b){
    return a + b
  }

  module.exports.sum = inSum
</wxs>

<view>{{  obj.sum(1,2)  }}</view>


或者

<wxs module = 'nba'>
    module.exports={
        yaoming:function(){
        return '姚明'
        },
        siji:function(){
        return '银角大王'
        }
    }
</wxs>
<view> {{ nba.yaoming() +'  : ' nba.siji()}}</view>
小程序的冒泡事件

bindxxx 是冒泡事件
catchxxx 是非冒泡事件

.father{
  width: 300rpx;
  height:300rpx;
  background-color: skyblue;
}

.son{
  width: 100rpx;
  height:100rpx;
  background-color: pink;
}

.son2 {
  width: 100rpx;
  height:100rpx;
  background-color: green;
}


<view class='father' bindtap='fatherHandle'>
父亲
    <view class='son' bindtap='sonHandle'>
      儿子1
    </view>
    <view class='son2' catchtap='son2Handle'>
      儿子2
    </view>
</view>

 fatherHandle(event){
    console.log("父亲被点击了")
  },
  sonHandle(event){
    console.log("儿子1被点击了")
  },
  son2Handle(event){
    console.log("儿子2被点击了")
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值