微信小程序之表单组件之slider(滑动选择器)+form(表单)+label(表单组件)详解

一.slider

 

slider 即 滑动选择器。

 

1.属性

 

 

2.代码

 

2.1.WXSS代码

.intro {
  margin: 10px;
}

 

2.2.WXML代码

<text class="intro">{{textValue}}</text>
<view class="intro">
  <slider bindchange="sliderchange" min="{{minValue}}" max="{{maxValue}}" block-size="20" value="{{showValue}}" show-value/>
</view>

 

2.3.JS代码

Page({

  /**
   * 页面的初始数据
   */
  data: {
    minValue:'0',
    showValue:'30',
    maxValue:'100',
    textValue: '设置最小/最大值:30'
  },

  /**
   * slider滑动监听事件
   */

  sliderchange:function(e){
    this.setData({
      textValue: '设置最小/最大值:'+e.detail.value
    })

    console.log(`当前值`, e.detail.value)
  }
})

 

 

3.效果

 

 

 

 

 

 

二.form

 

form 即 表单,将组件内的用户输入的<switch/> <input/> <checkbox/> <slider/> <radio/> <picker/>提交。

当点击 <form/>表单中 formType 为 submit 的<button/> 组件时,会将表单组件中的 value 值进行提交,需要在表单组件中加上 name 来作为 key。

 

1.属性

 

 

2.代码

 

2.1.WXML代码

<form bindsubmit="formSubmit" bindreset="formReset">
  <view class="section section_gap">
    <view class="section__title">switch</view>
    <switch name="switch"/>
  </view>
  <view class="section section_gap">
    <view class="section__title">slider</view>
    <slider name="slider" show-value ></slider>
  </view>

  <view class="section">
    <view class="section__title">input</view>
    <input name="input" placeholder="please input here" />
  </view>
  <view class="section section_gap">
    <view class="section__title">radio</view>
    <radio-group name="radio-group">
      <label><radio value="radio1"/>radio1</label>
      <label><radio value="radio2"/>radio2</label>
    </radio-group>
  </view>
  <view class="section section_gap">
    <view class="section__title">checkbox</view>
    <checkbox-group name="checkbox">
      <label><checkbox value="checkbox1"/>checkbox1</label>
      <label><checkbox value="checkbox2"/>checkbox2</label>
    </checkbox-group>
  </view>
  <view class="btn-area">
    <button type='primary' formType="submit">提交</button>
    <button type='warn' formType="reset">重置</button>
  </view>
</form>

 

2.2.JS代码

Page({
  formSubmit: function (e) {
    console.log('form发生了submit事件,携带数据为:', e.detail.value)
  },
  formReset: function () {
    console.log('form发生了reset事件')
  }
})

 

3.效果

 

 

 

 

 

 

 

三.label

 

label 即 用来改进表单组件的可用性,使用for属性找到对应的id,或者将控件放在该标签下,当点击时,就会触发对应的控件。

for优先级高于内部控件,内部有多个控件的时候默认触发第一个控件。

目前可以绑定的控件有:<button/>, <checkbox/>, <radio/>, <switch/>。

 

1.属性

 

 

2.代码

https://developers.weixin.qq.com/miniprogram/dev/component/label.html

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值