這篇文章主要為大家展示了微信小程序單選框如何自定義賦值,內(nèi)容簡而易懂,希望大家可以學(xué)習(xí)一下,學(xué)習(xí)完之后肯定會(huì)有收獲的,下面讓小編帶大家一起來看看吧。

創(chuàng)新互聯(lián)專注于企業(yè)全網(wǎng)營銷推廣、網(wǎng)站重做改版、五龍口網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5建站、商城建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為五龍口等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
知識(shí)點(diǎn):
1、理解wx:if作用
2、理解三元運(yùn)算符的使用
3、利用偽元素after/before自定義內(nèi)容
4、定時(shí)器setTimeout的使用
照例先上代碼
wxml部分:
<view class='input-list'>
<view class='list-l'>預(yù)計(jì)到店</view>
<view class='list-r' bindtap='powerDrawer' data-statu="open">
<view class='arriveTime'>{{item}}</view>
</view>
</view>
<view class="drawer_screen" wx:if="{{showModalStatus}}" bindtap="powerDrawer" data-statu="close" catchtouchmove="preventTouchMove"></view>
<!--content-->
<!--使用animation屬性指定需要執(zhí)行的動(dòng)畫-->
<view animation="{{animationData}}" class="drawer_box" wx:if="{{showModalStatus}}" catchtouchmove="preventTouchMove">
<view class='modalBox'>
<view class='choosePush grey9'>房間整晚保留,14:00之前到店可能需要等房</view>
<view class="{{_num == 0 ? 'choosePush t' : 'choosePush'}}" bindtap='chooseChecked' data-num='0' data-txt='18:00以前'>
18:00以前
<view class='checkbox' wx:if="{{_num==0}}"></view>
</view>
<view class="{{_num == 1 ? 'choosePush t' : 'choosePush'}}" bindtap='chooseChecked' data-num='1' data-txt='20:00以前'>
20:00以前
<view class='checkbox' wx:if="{{_num==1}}"></view>
</view>
<view class="{{_num == 2 ? 'choosePush t' : 'choosePush'}}" bindtap='chooseChecked' data-num='2' data-txt='23:59以前'>
23:59以前
<view class='checkbox' wx:if="{{_num==2}}"></view>
</view>
<view class="{{_num == 3 ? 'choosePush t' : 'choosePush'}}" bindtap='chooseChecked' data-num='3' data-txt='次日凌晨6:00之前'>
次日凌晨6:00之前
<view class='checkbox' wx:if="{{_num==3}}"></view>
</view>
</view>
</view>wxss部分:
.input-list {
padding: 40rpx;
border-bottom: 1px solid #eee;
display: flex;
position: relative;
}
.list-l {
flex: 2;
line-height: 50rpx;
}
.list-r {
flex: 5;
}
.arriveTime {
line-height: 50rpx;
}
.drawer_screen {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 1000;
background: #000;
opacity: 0.5;
overflow: hidden;
}
/*content*/
.drawer_box {
width: 100vw;
height: auto;
padding: 0;
overflow: hidden;
position: fixed;
bottom: 0;
left: 0;
z-index: 1001;
background: #fff;
}
.modalBox {
padding: 0 40rpx;
font-size: 30rpx;
}
.choosePush {
text-align: center;
padding: 40rpx 0 ;
border-bottom: 1px solid #eee;
position: relative
}
.choosePush.t {
color: #1da0ee;
}
.checkbox {
position: absolute;
right: 0;
top: 38rpx;
height: 40rpx;
width: 40rpx;
border: 1px solid #1da0ee;
}
.checkbox::after {
content: '';
position: absolute;
height: 15rpx;
width: 25rpx;
border-left: 1px solid #1da0ee;
border-bottom: 1px solid #1da0ee;
transform: rotate(-45deg);
top: 6rpx;
right: 6rpx;
}js部分:
Page({
data: {
showModalStatus: false,
_num: null,
haveChoosed: false,
sta: null,
item: '18:00',
},
preventTouchMove() { },
powerDrawer: function (e) {
console.log(e)
var currentStatu = e.currentTarget.dataset.statu;
this.util(currentStatu)
},
util: function (currentStatu) {
/* 動(dòng)畫部分 */
// 第1步:創(chuàng)建動(dòng)畫實(shí)例
var animation = wx.createAnimation({
duration: 200, //動(dòng)畫時(shí)長
timingFunction: "linear", //線性
delay: 0 //0則不延遲
});
// 第2步:這個(gè)動(dòng)畫實(shí)例賦給當(dāng)前的動(dòng)畫實(shí)例
this.animation = animation;
// 第3步:執(zhí)行第一組動(dòng)畫
animation.opacity(0).translateY(500).step();
// 第4步:導(dǎo)出動(dòng)畫對(duì)象賦給數(shù)據(jù)對(duì)象儲(chǔ)存
this.setData({
animationData: animation.export()
})
// 第5步:設(shè)置定時(shí)器到指定時(shí)候后,執(zhí)行第二組動(dòng)畫
setTimeout(function () {
// 執(zhí)行第二組動(dòng)畫
animation.opacity(1).translateY(0).step();
// 給數(shù)據(jù)對(duì)象儲(chǔ)存的第一組動(dòng)畫,更替為執(zhí)行完第二組動(dòng)畫的動(dòng)畫對(duì)象
this.setData({
animationData: animation
})
//關(guān)閉
if (currentStatu == "close") {
this.setData(
{
showModalStatus: false
}
);
}
}.bind(this), 200)
// 顯示
if (currentStatu == "open") {
this.setData(
{
showModalStatus: true
}
);
}
},
chooseChecked: function (e) {
console.log(e) //打印出來你會(huì)了解所設(shè)定參數(shù)的意義
this.setData({
_num: e.currentTarget.dataset.num,
item: e.currentTarget.dataset.txt,
})
setTimeout(function () {
this.setData(
{
showModalStatus: false
}
);
}.bind(this), 2000)
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad: function (options) {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面顯示
*/
onShow: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面隱藏
*/
onHide: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面卸載
*/
onUnload: function () {
},
/**
* 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作
*/
onPullDownRefresh: function () {
},
/**
* 頁面上拉觸底事件的處理函數(shù)
*/
onReachBottom: function () {
},
/**
* 用戶點(diǎn)擊右上角分享
*/
onShareAppMessage: function () {
}
})這是單選效果,復(fù)選效果 獲取其index(如wxml中屬性設(shè)定為 data-selectIndex=''{{index}}'' , 在js方法中打印出來對(duì)象的json數(shù)組,利用三元運(yùn)算添加class屬性完成),點(diǎn)擊它自身時(shí),改變其狀態(tài),最后setData已改變屬性的json數(shù)組。
以上就是關(guān)于微信小程序單選框如何自定義賦值的內(nèi)容,如果你們有學(xué)習(xí)到知識(shí)或者技能,可以把它分享出去讓更多的人看到。
分享標(biāo)題:微信小程序單選框如何自定義賦值
瀏覽路徑:http://www.chinadenli.net/article16/gghhdg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、網(wǎng)站排名、外貿(mào)建站、網(wǎng)站建設(shè)、微信小程序、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)