微信小程序 switch組件詳解及簡(jiǎn)單實(shí)例
更新時(shí)間:2017年01月10日 15:14:15 投稿:lqh
這篇文章主要介紹了微信小程序 switch組件詳解及簡(jiǎn)單實(shí)例 的相關(guān)資料,需要的朋友可以參考下
微信小程序switch
相關(guān)文章:
實(shí)現(xiàn)效果圖:
開(kāi)關(guān)選擇器
| 屬性名 | 類(lèi)型 | 默認(rèn)值 | 說(shuō)明 |
|---|---|---|---|
| checked | Boolean | false | 是否選中 |
| disabled | Boolean | false | 是否禁用 |
| type | String | switch | 樣式,有效值:switch, checkbox |
| bindchange | EventHandle | checked改變時(shí)觸發(fā)change事件,event.detail={ value:checked} |
示例代碼:
<view class="section section_gap">
<view class="section__title">type="switch"</view>
<view class="body-view">
<switch checked="{{switch1Checked}}" bindchange="switch1Change"/>
</view>
</view>
<view class="section section_gap">
<view class="section__title">type="checkbox"</view>
<view class="body-view">
<switch type="checkbox" checked="{{switch2Checked}}" bindchange="switch2Change"/>
</view>
</view>
var pageData = {
data: {
switch1Checked: true,
switch2Checked: false,
switch1Style: '',
switch2Style: 'text-decoration: line-through'
}
}
for(var i = 1; i <= 2; ++i) {
(function(index) {
pageData[`switch${index}Change`] = function(e) {
console.log(`switch${index}發(fā)生change事件,攜帶值為`, e.detail.value)
var obj = {}
obj[`switch${index}Checked`] = e.detail.value
this.setData(obj)
obj = {}
obj[`switch${index}Style`] = e.detail.value ? '' : 'text-decoration: line-through'
this.setData(obj)
}
})(i)
}
Page(pageData)
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
微信小程序上滑加載下拉刷新(onscrollLower)分批加載數(shù)據(jù)(一)
這篇文章主要介紹了微信小程序上滑加載下拉刷新(onscrollLower)分批加載數(shù)據(jù)的相關(guān)資料,需要的朋友可以參考下2017-05-05
微信小程序 實(shí)戰(zhàn)程序簡(jiǎn)易新聞的制作
這篇文章主要介紹了微信小程序 實(shí)戰(zhàn)程序簡(jiǎn)易新聞的制作的相關(guān)資料,需要的朋友可以參考下2017-01-01
JS中 querySelector 與 getElementById 方法區(qū)別
這篇文章主要介紹了JavaScript中 querySelector 與 getElementById 方法與區(qū)別,圍繞querySelector 與 getElementById 的相關(guān)資料展開(kāi)文章內(nèi)容,需要的朋友可以參考一下2021-10-10


