本文小編為大家詳細(xì)介紹“微信小程序怎么實(shí)現(xiàn)點(diǎn)擊控件后選中其它反選”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“微信小程序怎么實(shí)現(xiàn)點(diǎn)擊控件后選中其它反選”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識(shí)吧。

前言:
如果需要實(shí)現(xiàn)進(jìn)來進(jìn)行給按鈕加上買一送一的樣式,或者單擊就選中單個(gè)按鈕,只能靠css結(jié)合js進(jìn)行控制了,小程序暫時(shí)沒有這樣的控件。
實(shí)現(xiàn)效果圖:

微信小程序進(jìn)來的時(shí)候自動(dòng)進(jìn)行按鈕樣式的初始化,這個(gè)需要一個(gè)字段做判斷,加上正則表達(dá)式wxml文件:
<block wx:for="{{liuliangItems}}">
<block wx:if="{{item.one2one == 1}}">
<button class="{{item.changeColor?'selected2':'selected1'}}" type="default" id="{{item.price}}" data-id="{{item.name}}" data-one="{{item.one2one}}" data-orderid="{{item.id}}" data-number="1" bindtap="setPrice">{{item.name}}</button>
</block>
<block wx:else>
<button class="{{item.changeColor?'selected':'normal'}}" type="default" id="{{item.price}}" data-id="{{item.name}}" data-one="{{item.one2one}}" data-orderid="{{item.id}}" data-number="1" bindtap="setPrice">{{item.name}}</button>
</block>
</block>wxss文件
.normal{
box-sizing: border-box;
flex: 0 0 21%;
margin: 5px 5px;
height: 50px;
color:#1aad19;
border:1px solid #1aad19;
background-color:transparent;
}
.selected{
box-sizing: border-box;
flex: 0 0 21%;
margin: 5px 5px;
height: 50px;
background-color: #F75000;
color: white;
}
.selected1{
box-sizing: border-box;
flex: 0 0 21%;
margin: 5px 5px;
height: 50px;
background-color: transparent;
border:1px solid #1aad19;
color:#1aad19;
background-image: url(https://wxcx.llzt.net/images/hot.png) ;
background-position:31px 0px;
background-repeat:no-repeat;
background-size:62%;
}
.selected2{
box-sizing: border-box;
flex: 0 0 21%;
margin: 5px 5px;
height: 50px;
background-color: #F75000;
color: white;
background-image: url(https://wxcx.llzt.net/images/hot.png);
background-position:31px 0px;
background-repeat:no-repeat;
background-size:62%;
}現(xiàn)在的方法把集合進(jìn)行循環(huán),然后獲取當(dāng)前點(diǎn)擊的這個(gè)按鈕進(jìn)行比較,然后進(jìn)行樣式的修改
for (var i = 0; i < this.data.liuliangItems.length; i++) {
if (e.target.dataset.orderid == this.data.liuliangItems[i].id) {
txtArray1[i] = {
id: this.data.liuliangItems[i].id, changeColor: true,
price: this.data.liuliangItems[i].price, name: this.data.liuliangItems[i].name,
one2one: this.data.liuliangItems[i].one2one
}
} else {
txtArray1[i] = {
id: this.data.liuliangItems[i].id, changeColor: false,
price: this.data.liuliangItems[i].price, name: this.data.liuliangItems[i].name,
one2one: this.data.liuliangItems[i].one2one
}
}
}讀到這里,這篇“微信小程序怎么實(shí)現(xiàn)點(diǎn)擊控件后選中其它反選”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當(dāng)前名稱:微信小程序怎么實(shí)現(xiàn)點(diǎn)擊控件后選中其它反選-創(chuàng)新互聯(lián)
轉(zhuǎn)載來于:http://www.chinadenli.net/article6/despig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、服務(wù)器托管、品牌網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站內(nèi)鏈、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容