一.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