微信小程序开发--组件(4)

一、picker-view / picker-view-column

<view>
  <view>{{year}}年{{month}}月{{day}}日</view>
  <picker-view indicator-style="height: 50px;" style="width: 100%; height: 300px;" value="{{value}}" bindchange="bindChange">
    <picker-view-column>
      <view wx:for="{{years}}" style="line-height: 50px"wx:key="">{{item}}年</view>
    </picker-view-column>
    <picker-view-column>
      <view wx:for="{{months}}" style="line-height: 50px"wx:key="">{{item}}月</view>
    </picker-view-column>
    <picker-view-column>
      <view wx:for="{{days}}" style="line-height: 50px" wx:key="">{{item}}日</view>
    </picker-view-column>
  </picker-view>
</view>
<!-- 
value                    Array.<number>        数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),数字大于 picker-view-column                      可选项长度时,选择最后一项。    1.0.0
indicator-style          string                  设置选择器中间选中框的样式    1.0.0
indicator-class          string                  设置选择器中间选中框的类名    1.1.0
mask-style              string                  设置蒙层的样式    1.5.0
mask-class              string                  设置蒙层的类名    1.5.0
bindchange              eventhandle              滚动选择时触发change事件,event.detail = {value};value为数组,表示 picker-view 内的  picker-view-column                      当前选择的是第几项(下标从 0 开始)    1.0.0
bindpickstart            eventhandle              当滚动选择开始时候触发事件    2.3.1
bindpickend              eventhandle              当滚动选择结束时候触发事件
 -->
//index.js
//获取应用实例
const date = new Date()
const years = []
const months = []
const days = []

for (let i = 1990; i <= date.getFullYear(); i++) {
  years.push(i)
}

for (let i = 1; i <= 12; i++) {
  months.push(i)
}

for (let i = 1; i <= 31; i++) {
  days.push(i)
}

Page({
  data: {
    years: years,
    year: date.getFullYear(),
    months: months,
    month: 9,
    days: days,
    day: 25,
    value: [19999, 8, 24],
    // 数组中的三个元素分别表示:1、年份下标、月份下标、日期下标 
  },
  bindChange: function (e) {
    const val = e.detail.value
    this.setData({
      year: this.data.years[val[0]],
      month: this.data.months[val[1]],
      day: this.data.days[val[2]]
    })
  }
})

 二、textarea

<view class="content">
</view>
<view class="section">
  <textarea bindblur="bindTextAreaBlur" auto-height placeholder="自动变高" />
</view>
<view class="section">
  <textarea placeholder="placeholder颜色是红色的" placeholder-style="color:red;" />
</view>
<view class="section">
  <textarea placeholder="这是一个可以自动聚焦的textarea" auto-focus />
</view>
<view class="section">
  <textarea placeholder="这个只有在按钮点击的时候才聚焦" focus="{{focus}}" />
  <view class="btn-area">
    <button bindtap="bindButtonTap">使得输入框获取焦点</button>
  </view>
</view>
<view class="section">
  <form bindsubmit="bindFormSubmit">
    <textarea placeholder="form 中的 textarea" name="textarea" />
    <button form-type="submit"> 提交 </button>
  </form>
</view>
<!--      
value                          string             输入框的内容    1.0.0
placeholder                    string             输入框为空时占位符    1.0.0
placeholder-style              string             指定 placeholder 的样式,目前仅支持color,font-size和font-weight    1.0.0
placeholder-class              string           textarea-placeholder    否    指定 placeholder 的样式类    1.0.0
disabled                      boolean           是否禁用    1.0.0
maxlength                      number         最大输入长度,设置为 -1 的时候不限制最大长度    1.0.0
auto-focus                    boolean           自动聚焦,拉起键盘。    1.0.0
focus                          boolean           获取焦点    1.0.0
auto-height                    boolean           是否自动增高,设置auto-height时,style.height不生效    1.0.0
fixed    boolean                  false             如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixedtrue    1.0.0
cursor-spacing                number           指定光标与键盘的距离。取textarea距离底部的距离和cursor-spacing指定的距离的最小值作为光标与键盘的距离    
cursor                        number         指定focus时的光标位置    1.5.0
show-confirm-bar              boolean           是否显示键盘上方带有”完成“按钮那一栏    1.6.0
selection-start                number           光标起始位置,自动聚集时有效,需与selection-end搭配使用    1.9.0
selection-end                  number           光标结束位置,自动聚集时有效,需与selection-start搭配使用    1.9.0
adjust-position               boolean           键盘弹起时,是否自动上推页面    1.9.90
bindfocus                      eventhandle        输入框聚焦时触发,event.detail = { value, height },height 为键盘高度,在基础库 1.9.90 起支持    
bindblur                      eventhandle        输入框失去焦点时触发,event.detail = {value, cursor}    1.0.0
bindlinechange                eventhandle        输入框行数变化时调用,event.detail = {height: 0, heightRpx: 0, lineCount: 0}    1.0.0
bindinput                     eventhandle        当键盘输入时,触发 input 事件,event.detail = {value, cursor, keyCode},keyCode 为键值,目前工具还不支持返回keyCode参数。bindinput 处理函数的返回值并不会反映到 textarea 上    1.0.0
bindconfirm                    eventhandle        点击完成时, 触发 confirm 事件,event.detail = {value: value}    1.0.0
bindkeyboardheightchange      eventhandle        键盘高度发生变化的时候触发此事件,event.detail = {height: height, duration: duration
 -->
//textarea.js
Page({
  data: {
    height: 20,
    focus: false
  },
  bindButtonTap: function () {
    this.setData({
      focus: true
    })
  },
  bindTextAreaBlur: function (e) {
    console.log(e.detail.value)
  },
  bindFormSubmit: function (e) {
    console.log(e.detail.value.textarea)
  }
})

 

转载于:https://www.cnblogs.com/DreamchaserHe/p/11205247.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值