微信小程序弹出可填写框两种方法

方法一:

  html页面:

        

<view class="container" class="zn-uploadimg">

<button type="primary"bindtap="modalinput">modal有输入框</button>

</view>

<modal id="modal" hidden="{{hiddenmodalput}}" title="预约信息" confirm-text="提交" cancel-text="取消" bindcancel="cancel" bindconfirm="confirm">

<input type='text' placeholder="姓名:" auto-focus/>

<input type='number' placeholder="电话:" auto-focus/>

<input type='text' placeholder="人数:" auto-focus/>

<input type='text' placeholder="时间:" auto-focus/>

</modal>

    js页面:



//获取应用实例

var app = getApp()

Page({

data: {

hiddenmodalput: true,

//可以通过hidden是否掩藏弹出框的属性,来指定那个弹出框

},

//点击按钮痰喘指定的hiddenmodalput弹出框

modalinput: function () {

this.setData({

hiddenmodalput: !this.data.hiddenmodalput

})

},

//取消按钮

cancel: function () {

this.setData({

hiddenmodalput: true

});

},

//确认

confirm: function () {

this.setData({

hiddenmodalput: true

})

}

})

方法二:

html页面:

<button class="show-btn" bindtap="showDialogBtn">弹窗</button>

<!--弹窗-->

<view class="modal-mask" bindtap="hideModal" catchtouchmove="preventTouchMove" wx:if="{{showModal}}"></view>

<view class="modal-dialog" wx:if="{{showModal}}">

<view class="modal-title">预约信息</view>

<view class="modal-content">

<view class="modal-input">

<input placeholder-class="input-holder" type="number" maxlength="10" bindinput="inputChange" class="input" placeholder="姓名"></input>

</view>

<view class="modal-input">

<input placeholder-class="input-holder" type="number" maxlength="10" bindinput="inputChange" class="input" placeholder="电话"></input>

</view>

<view class="modal-input">

<input placeholder-class="input-holder" type="number" maxlength="10" bindinput="inputChange" class="input" placeholder="人数"></input>

</view>

<view class="modal-input">

<input placeholder-class="input-holder" type="number" maxlength="10" bindinput="inputChange" class="input" placeholder="时间"></input>

</view>

</view>

<view class="modal-footer">

<view class="btn-cancel" bindtap="onCancel" data-status="cancel">取消</view>

<view class="btn-confirm" bindtap="onConfirm" data-status="confirm">确定</view>

</view>

</view>

css页面:



/**index.wxss**/

.show-btn {

margin-top: 100rpx;

color: #22cc22;

}

.modal-mask {

width: 100%;

height: 100%;

position: fixed;

top: 0;

left: 0;

background: #000;

opacity: 0.5;

overflow: hidden;

z-index: 9000;

color: #fff;

}

.modal-dialog {

width: 540rpx;

overflow: hidden;

position: fixed;

top: 50%;

left: 0;

z-index: 9999;

background: #fff;

margin: -180rpx 105rpx;

border-radius: 36rpx;

}

.modal-title {

padding-top: 50rpx;

font-size: 36rpx;

color: #030303;

text-align: center;

}

.modal-content {

padding: 50rpx 32rpx;

}

.modal-input {

display: flex;

background: #fff;

border-bottom: 2rpx solid #ddd;

border-radius: 4rpx;

font-size: 28rpx;

}

.input {

width: 100%;

height: 82rpx;

font-size: 28rpx;

line-height: 28rpx;

padding: 0 20rpx;

box-sizing: border-box;

color: #333;

}

input-holder {

color: #666;

font-size: 28rpx;

}

.modal-footer {

display: flex;

flex-direction: row;

height: 86rpx;

border-top: 1px solid #dedede;

font-size: 34rpx;

line-height: 86rpx;

}

.btn-cancel {

width: 50%;

color: #666;

text-align: center;

border-right: 1px solid #dedede;

}

.btn-confirm {

width: 50%;

color: #ec5300;

text-align: center;

}

js页面:



/**

* 弹窗

*/

showDialogBtn: function () {



this.setData({

showModal: true

})

},

/**

* 弹出框蒙层截断touchmove事件

*/

preventTouchMove: function () {

},

/**

* 隐藏模态对话框

*/

hideModal: function () {

this.setData({

showModal: false

});

},

/**

* 对话框取消按钮点击事件

*/

onCancel: function () {

this.hideModal();

},

/**

* 对话框确认按钮点击事件

*/

onConfirm: function () {

wx.showToast({

title: '提交成功',

icon: 'success',

duration: 2000

})

this.hideModal();

}

方法一样式修改麻烦,但是代码简单

  • 14
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值