微信小程序 點擊控件后選中其它反選實例詳解
更新時間:2017年02月21日 14:50:15 投稿:lqh
這篇文章主要介紹了微信小程序 點擊控件后選中其它反選實例詳解的相關(guān)資料,需要的朋友可以參考下
微信小程序 點擊控件后選中其它反選實例詳解
前言:
如果需要實現(xiàn)進(jìn)來進(jìn)行給按鈕加上買一送一的樣式,或者單擊就選中單個按鈕,只能靠css結(jié)合js進(jìn)行控制了,小程序暫時沒有這樣的控件。
實現(xiàn)效果圖:

微信小程序進(jìn)來的時候自動進(jìn)行按鈕樣式的初始化,這個需要一個字段做判斷,加上正則表達(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)前點擊的這個按鈕進(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
}
}
}
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
您可能感興趣的文章:
- 微信小程序 實現(xiàn)點擊添加移除class
- 微信小程序?qū)崿F(xiàn)給循環(huán)列表添加點擊樣式實例
- 微信小程序?qū)崿F(xiàn)點擊按鈕修改view標(biāo)簽背景顏色功能示例【附demo源碼下載】
- 微信小程序?qū)崿F(xiàn)點擊按鈕修改字體顏色功能【附demo源碼下載】
- 微信小程序之綁定點擊事件實例詳解
- 微信小程序?qū)崿F(xiàn)點擊文字頁面跳轉(zhuǎn)功能【附源碼下載】
- 微信小程序加載更多 點擊查看更多
- 微信小程序點擊控件修改樣式實例詳解
- 微信小程序?qū)崿F(xiàn)點擊按鈕修改文字大小功能【附demo源碼下載】
- 微信小程序?qū)崿F(xiàn)點擊效果
相關(guān)文章
js以對象為索引的關(guān)聯(lián)數(shù)組
在代碼邏輯中更多的是用關(guān)聯(lián)數(shù)組的方式。但即使是這樣我們也很少使用對象類型作為鍵值對的鍵名。2010-07-07
微信小程序?qū)崿F(xiàn)搜索指定景點周邊美食、酒店
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)搜索指定景點周邊美食、酒店的功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-05-05

