您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)小程序中如何實(shí)現(xiàn)點(diǎn)擊控件后選中其它反選功能,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
前言:
如果需要實(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="pw_liuliangItems"> <block wx:if="pw_item.one2one == 1"> <button class="pw_item.changeColor?'selected2':'selected1'" type="default" id="pw_item.price" data-id="pw_item.name" data-one="pw_item.one2one" data-orderid="pw_item.id" data-number="1" bindtap="setPrice">pw_item.name</button> </block> <block wx:else> <button class="pw_item.changeColor?'selected':'normal'" type="default" id="pw_item.price" data-id="pw_item.name" data-one="pw_item.one2one" data-orderid="pw_item.id" data-number="1" bindtap="setPrice">pw_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
關(guān)于“小程序中如何實(shí)現(xiàn)點(diǎn)擊控件后選中其它反選功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。