微信小程序?qū)崿F(xiàn)自定義picker選擇器彈窗內(nèi)容
微信小程序中定義好的幾種picker選擇器,不管是日期選擇器還是地區(qū)選擇器,或是其他的都有定死的樣式和內(nèi)容。
例如:

但是大多數(shù)開(kāi)發(fā)程序的情況下還是需要自己寫樣式的,或是內(nèi)容的。
例如:

wxml
<view class="free-btns" style="margin-top: 10vh;background:none;">
<button class="free-btn" bindtap="toggleDialog">
選定國(guó)家:{{value}}
</button>
</view>
<view class="free-dialog {{ showDialog ? 'free-dialog--show' : '' }}">
<view class="free-dialog__mask" bindtap="toggleDialog" />
<view class="free-dialog__container">
<view style="padding: 5% 5% 15%;">
<form bindsubmit='submit' bindreset="reset">
<view bindtap='freetoBack' class="free-button free-dialog-reset">取消</view>
<view bindtap='freeBack' class="free-button free-dialog-submit">確定</view>
<radio-group class='free-radios' bindchange="radioChange">
<label class="free-radio" bindtap="click" wx:for="{{items}}" wx:key="{{items}}" data-id="{{index}}" style="{{index==id?'background:#48c23d;color:#fff;':'background:#fff;color:#000;'}}">
<radio value="{{item.name}}" name="{{item.value}}"></radio>
<label class="free-text">{{item.value}}</label>
</label>
</radio-group>
</form>
</view>
</view>
</view>
css
.free-dialog__mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 10;
background: rgba(0, 0, 0, 0.7);
display: none;
}
.free-dialog__container {
position: fixed;
left: 0;
bottom: 0;
width: 750rpx;
background: white;
transform: translateY(150%);
transition: all 0.4s ease;
z-index: 11;
}
.free-dialog--show .free-dialog__container {
transform: translateY(0);
}
.free-dialog--show .free-dialog__mask {
display: block;
}
/*模態(tài)框中的內(nèi)容*/
.free-button{
display: inline-block;
width:50px;
text-align: center;
font-size:20px;
color:#707070;
margin-bottom:20px;
}
.free-dialog-submit{
float: right;
color:#48c23d;
}
radio-group{
margin:10rpx 0rpx;
}
radio-group>label{
width:22.5%;
display: inline-block;
border:1px solid #ddd;
padding:10px 0px;
margin:0px 2px 2px;
}
radio-group label radio{
width:100%;
z-index: 3;
display: none;
}
.checked{
background:#48c23d;
color:#fff;
}
radio-group label .free-text{
width:100%;
text-align: center;
display: inline-block;
}
js
Page({
data: {
showDialog: false,
items: [
{ name: '中國(guó)', value: '中國(guó)' },
{ name: '美國(guó)', value: '美國(guó)' },
{ name: '巴西', value: '巴西' },
{ name: '日本', value: '日本' },
{ name: '英國(guó)', value: '英國(guó)' },
{ name: '法國(guó)', value: '法國(guó)' },
{ name: '韓國(guó)', value: '韓國(guó)' },
{ name: '俄羅斯', value: '俄羅斯' },]
},
/*點(diǎn)擊變色*/
click:function(e){
var id = e.currentTarget.dataset.id
var that = this
that.setData({
id:id
})
},
onLoad: function (options) {
var that = this
that.setData({
value:'show'
})
},
radioChange: function (e) {
console.log('radio發(fā)生change事件,攜帶value值為:', e.detail.value)
var that = this
that.setData({
value: e.detail.value
})
console.log(this.data.value)
},
toggleDialog() {
this.setData({
showDialog: !this.data.showDialog
});
},
freeBack:function(){
var that = this
if(this.data.value=='show'){
wx.showModal({
title: '提示',
content: '你沒(méi)有選擇任何內(nèi)容',
})
}
that.setData({
showDialog: !this.data.showDialog
})
},
freetoBack: function () {
var that = this
wx.showModal({
title: '提示',
content: '你沒(méi)有選擇任何內(nèi)容',
})
that.setData({
showDialog: !this.data.showDialog,
value:'show',
checked: false,
})
},
})
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS中Require與Import 區(qū)別對(duì)比分析
這篇文章主要為大家介紹了JS中Require與Import 區(qū)別對(duì)比分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
js 鍵盤記錄實(shí)現(xiàn)(兼容FireFox和IE)
用js實(shí)現(xiàn)鍵盤記錄,要關(guān)注瀏覽器的三種按鍵事件類型,即keydown,keypress和keyup,它們分別對(duì)應(yīng)onkeydown、onkeypress和onkeyup這三個(gè)事件句柄。一個(gè)典型的按鍵會(huì)產(chǎn)生所有這三種事件,依次是keydown,keypress,然后是按鍵釋放時(shí)候的keyup。2010-02-02
window.location.href和window.open窗口跳轉(zhuǎn)區(qū)別解析
這篇文章主要為大家介紹了window.location.href和window.open 跳轉(zhuǎn)區(qū)別解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07
JavaScript實(shí)現(xiàn)簡(jiǎn)單的輪播圖效果
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)簡(jiǎn)單的輪播圖效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06
如何將網(wǎng)頁(yè)表格內(nèi)容導(dǎo)入excel
這篇文章主要介紹了如何將網(wǎng)頁(yè)表格內(nèi)容導(dǎo)入excel,需要的朋友可以參考下2014-02-02
js網(wǎng)頁(yè)滾動(dòng)條滾動(dòng)事件實(shí)例分析
這篇文章主要介紹了js網(wǎng)頁(yè)滾動(dòng)條滾動(dòng)事件的用法,實(shí)例分析了javascript中window.onscroll監(jiān)控滾動(dòng)條滾動(dòng)事件的相關(guān)技巧,需要的朋友可以參考下2015-05-05
JavaScript使用concat連接數(shù)組的方法
這篇文章主要介紹了JavaScript使用concat連接數(shù)組的方法,實(shí)例分析了javascript中concat函數(shù)操作數(shù)組的技巧,需要的朋友可以參考下2015-04-04
JavaScript錯(cuò)誤處理try..catch...finally+涵蓋throw+TypeError+RangeEr
這篇文章主要介紹了JavaScript錯(cuò)誤處理:try..catch...finally+涵蓋throw+TypeError+RangeError,文章內(nèi)容具有一定的參考價(jià)值,需要的小伙伴可以參考一下,希望對(duì)你有所幫助2021-12-12

