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

方法一:

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();
}

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

原文地址:https://www.cnblogs.com/ziyoublog/p/10057600.html

时间: 2024-08-10 23:15:14

微信小程序弹出可填写框两种方法的相关文章

微信小程序--跳转页面常用的两种方法

一.bindtap="onProductsItemTap"绑定点击跳转事件 在.wxml文件中绑定 在.js文件中实现绑定事件函数 二.navigator标签配合URL跳转法 在wxml的代码 目标跳转页面的js文件

使用movable-view制作可拖拽的微信小程序弹出层效果。

仿了潮汐睡眠小程序的代码.[如果有侵权联系删除 最近做的项目有个弹出层效果,类似音乐播放器那种.按照普通的做了一般感觉交互不是很优雅,设计妹子把潮汐睡眠的弹层给我看了看,感觉做的挺好,于是乘着有空仿照了一下. 首先善用度娘反编译弄到了源码,但是打不开.然后自己研究源码发现他们用的是movable-view实现的. 于是仿照着搭出了基础框架. 新建了个组件 wxml <!--components/playpanel/playpanel.wxml--> <movable-area style

微信小程序弹出层

1.消息提示     wx.showToast wx.showToast({ title: '成功', icon: 'success', duration: 2000 }) 2.模态弹窗 wx.showModal wx.showModal({ title: '提示', content: '这是一个模态弹窗', success (res) { if (res.confirm) { console.log('用户点击确定') } else if (res.cancel) { console.log(

微信小程序弹出和隐藏遮罩层动画以及五星评分

参考源码: http://www.see-source.com/weixinwidget/detail.html?wid=82 https://blog.csdn.net/pcaxb/article/details/56276180 https://developers.weixin.qq.com/miniprogram/dev/api/api-animation.html train.wxml <view class='train_con'> <view class='head'>

微信小程序 - 弹出层组件

需要的可以下载示例:maskalert 原文地址:https://www.cnblogs.com/cisum/p/10421741.html

微信小程序用户拒绝授权的官方推荐处理方法

小程序开发中,现在一般都需要获取微信用户信息,如头像/名字等.这样在用户第一次进入小程序时,微信端会弹出一个是否同意授权的消息提示框.但是如果用户第一时间点击了拒绝,或者用户手误点击了拒绝,如果没有了后续的操作,可能你的小程序就不能使用了,也就会失去这样一位用户.所以,微信官方推荐了一个方法,就是在用户第一次拒绝授权的时候,再给用户一个选择的机会.这样能很好的解决上诉问题.下面以用户需要授权两个权限为例,方法如下: 在 APP.JS 先设置两个全局变量 .用作记录用户是否授权 //判断地理位置是

微信小程序开发—快速掌握组件及API的方法---转载

微信小程序框架为开发者提供了一系列的组件和API接口. 组件主要完成小程序的视图部分,例如文字.图片显示.API主要完成逻辑功能,例如网络请求.数据存储.音视频播放控制,以及微信开放的微信登录.微信支付等功能. 组件 官方文档:https://mp.weixin.qq.com/debug/wxadoc/dev/component/ 对于开发文档,个人建议先了解其整体框架,了解其提供了哪些组件,再联想到这些组件会用在哪些产品的哪些功能.对于接口也是一样,整体了解,而不需要细看. 熟悉了文档的结构,

微信小程序实现多张图片同时上传的方法

对于微信小程序上传图片其实很麻烦的,每次只能上传一张,所有很多朋友就会问想要多张图片上传怎么办?这里使用递归,当上传完一张图片后重新执行这个函数,直到所有的图片都上传完成后,就不再调用该函数了.具体的实现方法来为大家分享一下.示例代码如下: wx.chooseImage({success: function(res) {var tempFilePaths = res.tempFilePathswx.uploadFile({url: 'http://example.weixin.qq.com/up

微信小程序使用本地ip调试时报错解决方法

在微信小程序项目开发时,会用到本地调试,报错如下: 解决方法: 1.单击设置->项目设置 2.勾选该项即可. 原文地址:https://www.cnblogs.com/xindekaishi/p/12700768.html