使用小程序写一个弹窗输入组件

阅读 14261  ·  发布日期 2020-08-24 17:26  ·  温州雄霸网络科技有限公司|建站|APP小程序制作|做网站SEO推广优化
【摘要】 写项目的时候发现小程序没有自带的弹窗输入的组件,只能自己写一个。1.半透明的遮盖层遮盖层的样式和显隐事件wxml代码:eject'>弹窗 preventTouchMove' wx:if='{{showModal}}'>wxss代码:.model{ position: absolute; width:... 【温州小程序开发,温州微信公众号,平阳做网站,平阳网站建设公司,平阳小程序商城制作,昆阳万全做网站,鳌江水头小程序,萧江腾蛟微信公众号,山门顺溪南雁海西南麂凤卧麻步怀溪网络网店服务,政采云网店管理服务】...

使用小程序写一个弹窗输入组件

写项目的时候发现小程序没有自带的弹窗输入的组件,只能自己写一个。
1.半透明的遮盖层遮盖层的样式和显隐事件wxml代码:
preventTouchMove'
wx:if='
{
{
showModal}
}
'
>
wxss代码:
.model{
position: absolute;
width: 100%;
height: 100%;
background: #000;
z-index: 999;
opacity: 0.5;
top: 0;
left:0;
}
js代码:
/** * 页面的初始数据 */ data: {
showModal: false, }
, /** * 控制遮盖层的显示 */ eject:function(){
this.setData({
showModal:true }
) }
2.弹窗窗口实现弹窗窗口的样式和显隐事件wxml代码:
preventTouchMove'
wx:if='
{
{
showModal}
}
'
> windowRow'
> userTitle'
>标题
back'
bindtap='
back'
> 返回
wishName'
> wish_put'
placeholder='
请输入内容'
class='
wish_put'
>
wishbnt'
>
wxss代码:
.modalDlg{
width: 70%;
position: fixed;
top:350rpx;
left: 0;
right: 0;
z-index: 9999;
margin: 0 auto;
background-color: #fff;
border-radius: 10rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.windowRow{
display: flex;
flex-direction: row;
justify-content: space-between;
height: 110rpx;
width: 100%;
}
.back{
text-align: center;
color: #f7a6a2;
font-size: 30rpx;
margin: 30rpx;
}
.userTitle{
font-size: 30rpx;
color: #666;
margin: 30rpx;
}
.wishName{
width: 100%;
justify-content: center;
flex-direction: row;
display: flex;
margin-bottom: 30rpx;
}
.wish_put{
width: 80%;
border: 1px solid;
border-radius: 10rpx;
padding-left: 10rpx;
}
.wishbnt{
width: 100%;
font-size: 30rpx;
margin-bottom: 30rpx;
}
.wishbnt_bt{
width: 50%;
background-color: #f7a6a2;
color: #fbf1e8;
font-size: 30rpx;
border: 0;
}
js代码:
/** * 页面的初始数据 */ data: {
showModal: false, textV:'
'
}
, /** * 控制显示 */ eject:function(){
this.setData({
showModal:true }
) }
, /** * 点击返回按钮隐藏 */ back:function(){
this.setData({
showModal:false }
) }
, /** * 获取input输入值 */ wish_put:function(e){
this.setData({
textV:e.detail.value }
) }
, /** * 点击确定按钮获取input值并且关闭弹窗 */ ok:function(){
console.log(this.data.textV) this.setData({
showModal:false }
) }
3.完整代码最后献上完整代码,有点啰嗦了,想尽量详细点wxml代码:
preventTouchMove'
wx:if='
{
{
showModal}
}
'
>
preventTouchMove'
wx:if='
{
{
showModal}
}
'
> windowRow'
> userTitle'
>标题
back'
bindtap='
back'
> 返回
wishName'
> wish_put'
placeholder='
请输入内容'
class='
wish_put'
>
wishbnt'
>
wxss代码:
.body{
width: 100%;
height: 100%;
background-color: #fff;
position: fixed;
display: flex;
}
.body button{
height: 100rpx;
}
.model{
position: absolute;
width: 100%;
height: 100%;
background: #000;
z-index: 999;
opacity: 0.5;
top: 0;
left:0;
}
.modalDlg{
width: 70%;
position: fixed;
top:350rpx;
left: 0;
right: 0;
z-index: 9999;
margin: 0 auto;
background-color: #fff;
border-radius: 10rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.windowRow{
display: flex;
flex-direction: row;
justify-content: space-between;
height: 110rpx;
width: 100%;
}
.back{
text-align: center;
color: #f7a6a2;
font-size: 30rpx;
margin: 30rpx;
}
.userTitle{
font-size: 30rpx;
color: #666;
margin: 30rpx;
}
.wishName{
width: 100%;
justify-content: center;
flex-direction: row;
display: flex;
margin-bottom: 30rpx;
}
.wish_put{
width: 80%;
border: 1px solid;
border-radius: 10rpx;
padding-left: 10rpx;
}
.wishbnt{
width: 100%;
font-size: 30rpx;
margin-bottom: 30rpx;
}
.wishbnt_bt{
width: 50%;
background-color: #f7a6a2;
color: #fbf1e8;
font-size: 30rpx;
border: 0;
}
js代码:
Page({
/** * 页面的初始数据 */ data: {
showModal: false, textV:'
'
}
, /** * 控制显示 */ eject:function(){
this.setData({
showModal:true }
) }
, /** * 点击返回按钮隐藏 */ back:function(){
this.setData({
showModal:false }
) }
, /** * 获取input输入值 */ wish_put:function(e){
this.setData({
textV:e.detail.value }
) }
, /** * 点击确定按钮获取input值并且关闭弹窗 */ ok:function(){
console.log(this.data.textV) this.setData({
showModal:false }
) }
}
)推荐教程:
《微信小程序》以上就是使用小程序写一个弹窗输入组件的详细内容,更多请关注php中文网其它相关文章!
微信
分享相关标签:
小程序本文转载于:
简书,如有侵犯,请联系a@php.cn删除
上一篇:
Proxy 对象的了解及学习
下一篇:
小程序new Date()方法失效怎么办相关文章相关视频小程序swiper轮播CSS3动画及跳转到指定sw...微信小程序怎么使用车牌号输入法记一次微信小程序在安卓手机上的白屏问题新手必备的微信小程序开发指南使用小程序写一个弹窗输入组件百变小程序组件(下)小程序API接口(一)小程序API接口(二) [温州做小程序]