知識(shí)
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X(jué)表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營(yíng)銷(xiāo)的便利,運(yùn)營(yíng)的高效,讓網(wǎng)站成為營(yíng)銷(xiāo)工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!
您當(dāng)前位置>首頁(yè) » 新聞資訊 » 小程序相關(guān) >
微信小程序 點(diǎn)擊控件后選中其它反選實(shí)例詳解
發(fā)表時(shí)間:2021-1-11
發(fā)布人:葵宇科技
瀏覽次數(shù):47
前言:
如果需要實(shí)現(xiàn)進(jìn)來(lái)進(jìn)行給按鈕加上買(mǎi)一送一的樣式,或者單擊就選中單個(gè)按鈕,只能靠css結(jié)合js進(jìn)行控制了,小程序暫時(shí)沒(méi)有這樣的控件。
實(shí)現(xiàn)效果圖:
微信小程序進(jìn)來(lái)的時(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 } } }
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)案例查看更多
相關(guān)閱讀
- 微分銷(xiāo)
- 網(wǎng)站建設(shè)費(fèi)用
- 小程序用戶(hù)登錄
- 云南網(wǎng)站維護(hù)
- 網(wǎng)站建設(shè)招商
- 云南網(wǎng)絡(luò)營(yíng)銷(xiāo)顧問(wèn)
- 小程序分銷(xiāo)商城
- 網(wǎng)站建設(shè)開(kāi)發(fā)
- 開(kāi)發(fā)微信小程序
- 汽車(chē)報(bào)廢
- 商標(biāo)注冊(cè)
- 云南網(wǎng)站建設(shè)百度官方
- 云南建設(shè)廳網(wǎng)站首頁(yè)
- 昆明小程序定制開(kāi)發(fā)
- 保險(xiǎn)網(wǎng)站建設(shè)公司
- 云南小程序開(kāi)發(fā)推薦
- 小程序開(kāi)發(fā)聯(lián)系方式
- 云南網(wǎng)站建設(shè)特性
- 網(wǎng)站優(yōu)化公司
- 云南小程序開(kāi)發(fā)
- 云南小程序制作
- 報(bào)廢車(chē)回收管理軟件
- 北京小程序開(kāi)發(fā)
- 云南網(wǎng)站建設(shè)高手
- 云南手機(jī)網(wǎng)站建設(shè)
- 網(wǎng)站制作哪家好
- 搜索引擎排名
- 網(wǎng)站沒(méi)排名
- 云南軟件公司
- 小程序開(kāi)發(fā)課程