微信小程序?qū)崿F(xiàn)文本輸入彈窗
場(chǎng)景
用戶進(jìn)入界面彈出輸入窗口,需要用戶輸入內(nèi)容,如果取消則跳轉(zhuǎn)到指定界面,重新進(jìn)入還會(huì)彈出窗口,只有輸入正確內(nèi)容才能正式進(jìn)入此界面
實(shí)現(xiàn)
wxml
<view class="container">
? <view wx:if="{{!completed}}">
? ? <view class='toast-box'>
? ? ? <view class='toastbg'></view>
? ? ? <view class='showToast'>
? ? ? ? <view class='toast-title'>
? ? ? ? ? <text>確認(rèn)底金?</text>
? ? ? ? </view>
? ? ? ? <view class='toast-main'>
? ? ? ? ? <view class='toast-input'>
? ? ? ? ? ? <input type='number' placeholder='請(qǐng)輸入符合您的保底金額~' focus="true" bindinput='getUserInput'></input>
? ? ? ? ? </view>
? ? ? ? </view>
? ? ? ? <view class='toast-button'>
? ? ? ? ? <view class='cancel'>
? ? ? ? ? ? <button bindtap="cancelSelected">取消</button>
? ? ? ? ? </view>
? ? ? ? ? <view class='success'>
? ? ? ? ? ? <button bindtap="successSelected">確定</button>
? ? ? ? ? </view>
? ? ? ? </view>
? ? ? </view>
? ? </view>
? </view>
</view>wxss
.container {
? width: 100%;
? min-height: 100vh;
? background-color: #101419;
}
.toast-box {
? width: 100%;
? height: 100%;
? opacity: 1;
? position: fixed;
? top: 0px;
? left: 0px;
}
.toastbg {
? opacity: 0.2;
? background-color: black;
? position: absolute;
? width: 100%;
? min-height: 100vh;
}
.showToast {
? position: absolute;
? opacity: 1;
? width: 70%;
? margin-left: 15%;
? margin-top: 40%;
}
.toast-title {
? padding-left: 5%;
? background-color: #2196f3;
? color: white;
? padding-top: 2vh;
? padding-bottom: 2vh;
? border-top-right-radius: 16rpx;
? border-top-left-radius: 16rpx;
}
.toast-main {
? padding-top: 2vh;
? padding-bottom: 2vh;
? background-color: white;
? text-align: center;
}
.toast-input {
? margin-left: 5%;
? margin-right: 5%;
? border: 1px solid #ddd;
? padding-left: 2vh;
? padding-right: 2vh;
? padding-top: 1vh;
? padding-bottom: 1vh;
}
.toast-button {
? display: flex;
}
.cancel, .success {
? width: 50%;
}
.cancel button {
? color: #999;
? width: 100%;
? background-color: white;
? border-radius: 0px;
? border-bottom-left-radius: 16rpx;
}
.success button {
? color: #1d2228;
? width: 100%;
? background-color: white;
? border-radius: 0px;
? border-bottom-right-radius: 16rpx;
}js
Page({
? /**
? ?* 頁(yè)面的初始數(shù)據(jù)
? ?*/
? data: {
? ? completed: false, ?// 彈窗控制
? ? deposit: 0 ?// 存儲(chǔ)用戶輸入的內(nèi)容
? },
? // 獲取用戶輸入的內(nèi)容
? getUserInput(event) {
? ? const money = event.detail.value || event.detail.text
? ? this.setData({deposit: money})
? },
? // 取消按鈕觸發(fā)事件
? cancelSelected(event) {
? ? wx.switchTab({
? ? ? url: '/pages/optional/optional',
? ? })
? },
? // 確定按鈕觸發(fā)事件
? successSelected(event) {
? ? if (!(/(^[0-9]*$)/.test(this.data.deposit))) {
? ? ? wx.showToast({
? ? ? ? title: '只能輸入純數(shù)字',
? ? ? ? icon: 'none',
? ? ? ? duration: 2000
? ? ? })
? ? } else {
? ? ? this.setData({completed: true})
? ? }
? },
})效果圖

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
純javascript實(shí)現(xiàn)選擇框的全選與反選功能
這篇文章主要介紹了純javascript實(shí)現(xiàn)選擇框的全選與反選 ,需要的朋友可以參考下2019-04-04
JavaScript?setTimeout和setInterval的用法與區(qū)別詳解
Javascript的setTimeOut和setInterval函數(shù)應(yīng)用非常廣泛,它們都用來(lái)處理延時(shí)和定時(shí)任務(wù),下面這篇文章主要給大家介紹了關(guān)于JavaScript?setTimeout和setInterval的用法與區(qū)別,需要的朋友可以參考下2022-04-04
JS中new?Blob()詳解及blob轉(zhuǎn)file示例
這篇文章主要給大家介紹了關(guān)于JS中new?Blob()詳解及blob轉(zhuǎn)file的相關(guān)資料,Blob?Blob(Binary?Large?Object)表示二進(jìn)制類型的大對(duì)象,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-11-11
基于BootStrap柵格欄系統(tǒng)完成網(wǎng)站底部版權(quán)信息區(qū)
網(wǎng)站底部版權(quán)信息區(qū)可以用bootstrap的“柵格系統(tǒng)”完成,下面給大家分享一個(gè)未經(jīng)處理的底部版權(quán)信息區(qū)的樣式,大家可以做個(gè)參考2016-12-12
純js代碼制作的網(wǎng)頁(yè)時(shí)鐘特效【附實(shí)例】
下面小編就為大家?guī)?lái)一篇純js代碼制作的網(wǎng)頁(yè)時(shí)鐘特效【附實(shí)例】。小編覺(jué)得聽錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-03-03

