微信小程序?qū)崿F(xiàn)彈出輸入框代碼實(shí)例
1.微信自帶組件
樣式:

wxml
<view class="close" bindtap="close">拒絕</view>
js
Page({
//拒絕
close(e) {
wx.showModal({
editable:true,//顯示輸入框
placeholderText:'輸入拒絕原因',//顯示輸入框提示信息
success: res => {
if (res.confirm) { //點(diǎn)擊了確認(rèn)
console.log(res.content)//用戶輸入的值
} else {
console.log('用戶點(diǎn)擊了取消')
}
}
})
},
})詳見:wx.showModal(Object object) | 微信開放文檔
2.自定義組件
樣式:

wxml
<view class="close" bindtap="close">拒絕</view><!--點(diǎn)擊拒絕彈出-->
<block wx:if="{{isShowConfirm}}">
<view class='toast-box'>
<view class='toastbg'></view>
<view class='showToast'>
<view class='toast-main'>
<view class='toast-input'>
<input type='text' bindinput='setValue' placeholder="請(qǐng)輸入拒絕原因" data-name='stuEidtName'></input>
</view>
</view>
<view class='toast-button'>
<view class='button1'>
<view catchtap='cancel'>取消</view>
</view>
<view class='button2'>
<view catchtap='confirmAcceptance'>確定</view>
</view>
</view>
</view>
</view>
</block>wxss
/* 彈出窗 */
.toast-box {
width: 100%;
height: 100%;
opacity: 1;
position: fixed;
top: 0px;
left: 0px;
}
.toastbg {
opacity: 0.5;
background-color: black;
position: absolute;
width: 100%;
min-height: 100vh;
}
.showToast {
position: absolute;
opacity: 1;
width: 80%;
margin-left: 10%;
margin-top: 70%;
}
.toast-main {
padding-top: 2vh;
padding-bottom: 2vh;
background-color: white;
text-align: center;
border-top-left-radius: 16rpx;
border-top-right-radius: 16rpx;
}
.toast-input {
margin-left: 5%;
margin-right: 5%;
margin-top:10%;
margin-bottom:10%;
background-color: rgb(240, 240, 240);
padding-left: 2vh;
padding-right: 2vh;
padding-top: 1vh;
padding-bottom: 1vh;
}
.toast-input input{
background-color: rgb(240, 240, 240);
}
.toast-button {
display: flex;
background-color: white;
height:50px;
width:100%;
border-radius: 0px;
border-bottom-left-radius: 16rpx;
border-bottom-right-radius: 16rpx;
border-top:1px solid rgb(211, 211, 211);
}
.button1 {
width: 50%;
display: flex;
align-items: center;
justify-content: center;
border-radius: 0px;
border-bottom-left-radius: 16rpx;
}
.button2 {
width: 50%;
border-left:1px solid rgb(211, 211, 211);
display: flex;
align-items: center;
justify-content: center;
color:#40A4D6;
}js
Page({
data: {
isShowConfirm:false
},
//輸入框中的值
setValue: function (e) {
this.setData({
walletPsd: e.detail.value
})
},
//點(diǎn)擊取消按鈕
cancel: function () {
var that = this
that.setData({
isShowConfirm: false,
})
},
//點(diǎn)擊確認(rèn)按鈕
confirmAcceptance:function(){
var that = this
that.setData({
isShowConfirm: false,
})
},
//拒絕
close(e) {
this.setData({
isShowConfirm: true,
})
},
})3.多文本框
樣式:

wxml
<view class="update" bindtap="update" data-statu="open">修改</view>
<!--彈出框-->
<view class="drawer_screen" bindtap="update" data-statu="close" wx:if="{{showModalStatus}}"></view>
<!--content-->
<!--使用animation屬性指定需要執(zhí)行的動(dòng)畫-->
<view class="animation_position">
<view animation="{{animationData}}" class="drawer_box" wx:if="{{showModalStatus}}">
<!--drawer content-->
<view class="drawer_title">修改信息</view>
<view class="drawer_content">
<view class="grid">
<label class="title col-0">報(bào)修人員:</label>
<input class="input_base input_h30 col-1" bindblur="name" placeholder="請(qǐng)輸入報(bào)修人員姓名"></input>
</view>
<view class="grid">
<label class="title col-0">聯(lián)系電話:</label>
<input class="input_base input_h30 col-1" bindblur="phone" placeholder="請(qǐng)輸入報(bào)修人員電話"></input>
</view>
<view class="grid">
<label class="title col-0">維修產(chǎn)品:</label>
<input class="input_base input_h30 col-1" bindblur="product" placeholder="請(qǐng)輸入維修產(chǎn)品名稱"></input>
</view>
<view class="grid">
<label class="title col-0">故障類型:</label>
<input class="input_base input_h30 col-1" bindblur="type" placeholder="請(qǐng)輸入故障類型"></input>
</view>
<view class="bottom grid">
<label class="title col-0">故障地點(diǎn):</label>
<input class="input_base input_h30 col-1" bindblur="address" placeholder="請(qǐng)輸入地點(diǎn)"></input>
</view>
<view class="bottom grid">
<label class="title col-0">故障描述:</label>
<input class="input_base input_h30 col-1" bindblur="description" placeholder="請(qǐng)輸入故障描述"></input>
</view>
</view>
<view class="btn_ok" bindtap="update" data-statu="close">確定</view>
</view>
</view>wxss
/* 隱藏內(nèi)容樣式 */
/*mask*/
.drawer_screen {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 1000;
background: #000;
opacity: 0.5;
overflow: hidden;
}
/*content*/
.animation_position{
display: flex;
width:100%;
justify-content: center;
}
.drawer_box{
overflow: hidden;
position: fixed;
/* top:80px; */
bottom:90px;
z-index: 1001;
background: #FAFAFA;
border-radius: 3px;
width: 90%;
}
.drawer_title {
padding: 15px;
font: 20px "microsoft yahei";
text-align: center;
}
.drawer_content {
overflow-y: scroll;
/*超出父盒子高度可滾動(dòng)*/
}
.btn_ok {
margin-top:5%;
padding: 10px;
font: 20px "microsoft yahei";
text-align: center;
border-top: 1px solid #E8E8EA;
color: #40A4D6;
}
.bottom {
padding-bottom: 8px;
}
.title {
display: flex;
align-items: center;
justify-content: center;
width: 25%;
margin:5% 0 0 0;
border-bottom: 2rpx solid #ccc;
}
.input_base {
width:75%;
margin:5% 0 0 0;
padding-left:5%;
border-bottom: 2rpx solid #ccc;
}
input {
font: 15px "microsoft yahei";
background: #fff;
color: #000;
}
.grid {
display: flex;
margin:20px;
}js
const app = getApp()
let id = ''
let name = ''
let phone = ''
let product = ''
let type = ''
let address = ''
let description = ''
Page({
data: {
showModalStatus: false,
},
//信息修改
//獲取用戶輸入信息
name(event) { //獲取報(bào)修人員姓名
name = event.detail.value
console.log("name", name)
},
phone(event) { //獲取手機(jī)號(hào)
phone = event.detail.value
console.log("phone", phone)
},
product(event) { //維修產(chǎn)品
product = event.detail.value
console.log("produc", product)
},
type(event) { //故障類型
type = event.detail.value
console.log("type", type)
},
address(event) { //地址
address = event.detail.value
console.log("address", address)
},
description(event) { //描述
description = event.detail.value
console.log("description", description)
},
update: function (e) {
var currentStatu = e.currentTarget.dataset.statu;
this.util(currentStatu)
},
util: function (currentStatu) {
/* 動(dòng)畫部分 */
// 第1步:創(chuàng)建動(dòng)畫實(shí)例
var animation = wx.createAnimation({
duration: 200, //動(dòng)畫時(shí)長
timingFunction: "linear", //線性
delay: 0 //0則不延遲
});
// 第2步:這個(gè)動(dòng)畫實(shí)例賦給當(dāng)前的動(dòng)畫實(shí)例
this.animation = animation;
// 第3步:執(zhí)行第一組動(dòng)畫
animation.opacity(0).rotateX(-100).step();
// 第4步:導(dǎo)出動(dòng)畫對(duì)象賦給數(shù)據(jù)對(duì)象儲(chǔ)存
this.setData({
animationData: animation.export()
})
// 第5步:設(shè)置定時(shí)器到指定時(shí)候后,執(zhí)行第二組動(dòng)畫
setTimeout(function () {
// 執(zhí)行第二組動(dòng)畫
animation.opacity(1).rotateX(0).step();
// 給數(shù)據(jù)對(duì)象儲(chǔ)存的第一組動(dòng)畫,更替為執(zhí)行完第二組動(dòng)畫的動(dòng)畫對(duì)象
this.setData({
animationData: animation
})
//關(guān)閉
if (currentStatu == "close") {
this.setData({
showModalStatus: false
});
}
}.bind(this), 200)
// 顯示
if (currentStatu == "open") {
this.setData({
showModalStatus: true
});
}
},
})總結(jié)
到此這篇關(guān)于微信小程序?qū)崿F(xiàn)彈出輸入框的文章就介紹到這了,更多相關(guān)小程序彈出輸入框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaScript實(shí)現(xiàn)頁面中錄音功能的方法
這篇文章主要給大家介紹了關(guān)于JavaScript實(shí)現(xiàn)頁面中錄音功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用JavaScript具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06
js與jquery獲取父級(jí)元素,子級(jí)元素,兄弟元素的實(shí)現(xiàn)方法
本篇文章主要是對(duì)js與jquery獲取父級(jí)元素,子級(jí)元素,兄弟元素的實(shí)現(xiàn)方法進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2014-01-01
詳解JavaScript什么情況下不建議使用箭頭函數(shù)
箭頭函數(shù)作為ES6新增的語法,在使用時(shí)不僅能使得代碼更加簡潔,而且在某些場景避免this指向問題。但是箭頭函數(shù)不是萬能的,也有自己的缺點(diǎn)以及不適用的場景,本文總結(jié)了JavaScript什么情況下不建議使用箭頭函數(shù),感興趣的可以了解一下2022-06-06
小程序input數(shù)據(jù)雙向綁定實(shí)現(xiàn)方法
這篇文章主要介紹了小程序input數(shù)據(jù)雙向綁定實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
JavaScript高仿支付寶倒計(jì)時(shí)頁面及代碼實(shí)現(xiàn)
在支付寶上我們經(jīng)常會(huì)見到支付寶倒計(jì)時(shí)功能,倒計(jì)時(shí)應(yīng)用非常廣泛,下文給大家介紹js制作支付寶倒計(jì)時(shí)功能,但是里面涉及到,倒計(jì)時(shí),彈框,以及字體圖的相關(guān)知識(shí),感興趣的朋友一起看看吧2016-10-10
javascript 封裝的一個(gè)實(shí)用的焦點(diǎn)圖切換效果
之前有一篇博客,實(shí)用的焦點(diǎn)圖切換效果,結(jié)構(gòu)行為相分離 解釋的比較詳細(xì),腳本是分離式的,但在易用性和重用性方面并不理想,這里原作者進(jìn)行了,優(yōu)化。2010-07-07
JavaScript數(shù)據(jù)類型和變量_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要為大家詳細(xì)介紹了JavaScript數(shù)據(jù)類型和變量的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
javascript將DOM節(jié)點(diǎn)添加到文檔的方法實(shí)例分析
這篇文章主要介紹了javascript將DOM節(jié)點(diǎn)添加到文檔的方法,對(duì)比分析了javascript的兩種節(jié)點(diǎn)創(chuàng)建的方法,涉及javascript節(jié)點(diǎn)操作及運(yùn)行時(shí)間計(jì)算的相關(guān)技巧,需要的朋友可以參考下2015-08-08

