This article mainly introduces the relevant information on the implementation of input input and dynamic setting buttons of the WeChat applet. I hope this article can help everyone. Friends in need can refer to it. I hope it can help everyone.
Implementation of WeChat applet input input and dynamic setting button
[Requirement] When the mobile phone number has been filled in and the agreement has been checked, the "immediately" The "Login" button becomes bright and can be clicked; if any of the buttons are not satisfied, the button is grayed out and cannot be clicked; the SMS verification code is obtained, and the countdown prompts the operation; a toast pop-up window prompts the content that does not meet the requirements.
<view class="container"> <!--手机号--> <view class="section"> <text class="txt">手机号</text> <input value="{{mobile}}" placeholder-class="placeholder" placeholder="11位手机号码" type="number" maxlength="11" bindinput="mobileInput"/> </view> <!--图片验证码--> <view class="section"> <view> <text class="txt">图形验证码</text> <input placeholder-class="placeholder" placeholder="输入图形验证码" type="text" maxlength="4" bindinput="imgCaptchaInput"/> </view> <image class="imgBtn" src="{{imgCodeSrc}}" bindtap="getImgCode"></image> </view> <!--短信验证码--> <view class="section"> <view> <text class="txt">验证码</text> <input placeholder-class="placeholder" placeholder="输入验证码" type="number" maxlength="6" bindinput="smsCaptchaInput"/> </view> <view class="smsBtn" bindtap="getSMS">{{captchaText}}</view> </view> <view class="agree" style="margin-top:40rpx"> <checkbox-group bindchange="checkboxChange"> <checkbox class="check" value="1" checked="true" bindchange="checkboxChange"></checkbox> </checkbox-group> <span>已阅读并同意</span> <text style="color:#98c7ff" bindtap="xieyi">《用户使用协议》</text> </view> <view class="regist {{phoneAll&&checkAgree?'active':''}}" bindtap="regist">立即登录</view> </view> <!--mask--> <view class="toast_mask" wx:if="{{isShowToast}}"></view> <!--以下为toast显示的内容--> <view class="toast_content_box" wx:if="{{isShowToast}}"> <view class="toast_content"> <view class="toast_content_text"> {{toastText}} </view> </view> </view>
js
##
// 获取全局应用程序实例对象 const app = getApp() Page({ data: { //toast默认不显示 isShowToast: false, mobile: '', imgCode: '', code: '', // inviteCode: '', errorContent: '请输入手机号', timer: 60, captchaText: '获取验证码', captchaSended: false, isReadOnly: false, capKey: '', sendRegist: false, imgCodeSrc: '', phoneAll: false, checkAgree:true, checkboxValue:[1], }, // 显示弹窗 showToast(txt, duration = 1500) { //设置toast时间,toast内容 this.setData({ count: duration, toastText: txt }); var _this = this; // toast时间 _this.data.count = parseInt(_this.data.count) ? parseInt(_this.data.count) : 3000; // 显示toast _this.setData({ isShowToast: true, }); // 定时器关闭 setTimeout(function () { _this.setData({ isShowToast: false }); }, _this.data.count); }, // 双向绑定mobile mobileInput(e) { this.setData({ mobile: e.detail.value }); if(this.data.mobile.length===11){ this.setData({ phoneAll: true }); }else if(this.data.mobile.length<11){ this.setData({ phoneAll: false }); } }, // 双向绑定img验证码 imgCaptchaInput(e) { this.setData({ imgCode: e.detail.value }); }, // 双向绑定sms验证码 smsCaptchaInput(e) { this.setData({ code: e.detail.value }); }, // 同意协议 checkboxChange(e) { this.data.checkboxValue = e.detail.value; if(this.data.checkboxValue[0]==1){ this.setData({ checkAgree: true }); }else { this.setData({ checkAgree: false }); } }, // 获取短信验证码 getSMS() { var that = this.data; if (!that.mobile) { this.showToast('请输入手机号'); } else if (that.mobile.length != 11 || isNaN(that.mobile)) { this.showToast('请输入正确手机号'); } else if (that.imgCode.length != 4) { this.showToast('请输入正确图片验证码'); } else { if (that.captchaSended) return; this.setData({ captchaSended: true }) app.api.getSMSByMobileAndCaptcha({ mobile: that.mobile, capKey: that.capKey, code: that.imgCode, type:1 }).then((result) => { this.showToast(result.message); if (result.code != 1) { this.getImgCode(); this.setData({ captchaSended: false, }); } else { var counter = setInterval(() => { that.timer--; this.setData({ timer: that.timer, captchaText: `${that.timer}秒`, isReadOnly: true }); if (that.timer === 0) { clearInterval(counter); that.captchaSended = false; that.captchaText = '获取验证码'; this.setData({ timer: 60, captchaText: '获取验证码', captchaSended: false }) } }, 1000); } }); } }, // 获取图形码 getImgCode() { var capKey = "zdx-weixin" + Math.random(); this.setData({ imgCodeSrc: "http://prezdx.geinihua.com/invite/WeChat/verify?capKey=" + capKey, capKey: capKey }); }, //用户使用协议 xieyi() { wx.navigateTo({ url: '../userXieyi/userXieyi' }) }, // 注册 regist() { var that = this.data; if(!that.checkAgree||!that.phoneAll){ return } // sessionCheck为1,目的是防止微信code码先于session过期 var code = wx.getStorageSync('wxCode'); var sessionCheck = wx.getStorageSync('sessionCheck'); wx.setStorageSync('mobile',that.mobile); if (!that.mobile) { this.showToast('请输入手机号'); } else if (that.mobile.length != 11 || isNaN(that.mobile)) { this.showToast('请输入正确手机号'); } else if (that.code.length != 6) { this.showToast('请输入正确验证码'); } else { wx.showLoading({ title: '加载中...', }); app.api.loginByCaptcha({ mobile: that.mobile, smsCode: that.code, code: code, sessionCheck:sessionCheck, }).then((res) => { wx.hideLoading(); if (res.code == 2||res.code==1) { //注册成功 wx.setStorageSync('token', res.businessObj.token); wx.setStorageSync('userId',res.businessObj.userId); this.sucessCb(res); app.globalData.isLogin = true; //设置为登录成功 } else { this.showToast(res.message); } }); } }, // 成功回调 sucessCb(res) { wx.redirectTo({ url: '/pages/index/index' }) }, onLoad: function () { this.getImgCode(); var that=this; if(wx.getStorageSync('mobile')){ that.setData({ mobile: wx.getStorageSync('mobile'), }) } if(this.data.mobile.length===11){ this.setData({ phoneAll: true }); } }, })Related recommendations:
vue Get Detailed explanation of input input value
javascript input input box fuzzy prompt function detailed explanation
Detailed explanation of WeChat development input input box
The above is the detailed content of Detailed explanation of WeChat applet input input examples. For more information, please follow other related articles on the PHP Chinese website!

随着移动互联网技术和智能手机的普及,微信成为了人们生活中不可或缺的一个应用。而微信小程序则让人们可以在不需要下载安装应用的情况下,直接使用小程序来解决一些简单的需求。本文将介绍如何使用Python来开发微信小程序。一、准备工作在使用Python开发微信小程序之前,需要安装相关的Python库。这里推荐使用wxpy和itchat这两个库。wxpy是一个微信机器

小程序能用react,其使用方法:1、基于“react-reconciler”实现一个渲染器,生成一个DSL;2、创建一个小程序组件,去解析和渲染DSL;3、安装npm,并执行开发者工具中的构建npm;4、在自己的页面中引入包,再利用api即可完成开发。

laravel input隐藏域的实现方法:1、找到并打开Blade模板文件;2、在Blade模板中使用method_field方法来创建隐藏域,其创建语法是“{{ method_field('DELETE') }}”。

准备工作用vuecreateexample创建项目,参数大概如下:用原生input原生的input,主要是value和change,数据在change的时候需要同步。App.tsx如下:import{ref}from'vue';exportdefault{setup(){//username就是数据constusername=ref('张三');//输入框变化的时候,同步数据constonInput=;return()=>({

微信小程序是一种轻量级的应用程序,可以在微信平台上运行,不需要下载安装,方便快捷。Java语言作为一种广泛应用于企业级应用开发的语言,也可以用于微信小程序的开发。在Java语言中,可以使用SpringBoot框架和第三方工具包来开发微信小程序。下面是一个简单的微信小程序开发过程。创建微信小程序首先,需要在微信公众平台上注册一个小程序。注册成功后,可以获取到

实现思路x01服务端的建立首先,在服务端,使用socket进行消息的接受,每接受一个socket的请求,就开启一个新的线程来管理消息的分发与接受,同时,又存在一个handler来管理所有的线程,从而实现对聊天室的各种功能的处理x02客户端的建立客户端的建立就要比服务端简单多了,客户端的作用只是对消息的发送以及接受,以及按照特定的规则去输入特定的字符从而实现不同的功能的使用,因此,在客户端这里,只需要去使用两个线程,一个是专门用于接受消息,一个是专门用于发送消息的至于为什么不用一个呢,那是因为,只

PHP与小程序的地理位置定位与地图显示地理位置定位与地图显示在现代科技中已经成为了必备的功能之一。随着移动设备的普及,人们对于定位和地图显示的需求也越来越高。在开发过程中,PHP和小程序是常见的两种技术选择。本文将为大家介绍PHP与小程序中的地理位置定位与地图显示的实现方法,并附上相应的代码示例。一、PHP中的地理位置定位在PHP中,我们可以使用第三方地理位

Vue.js是一种轻量级的JavaScript框架,具有易用、高效和灵活的特点,是目前广受欢迎的前端框架之一。在Vue.js中,input框绑定事件是一个十分常见的需求,本文将详细介绍Vue文档中的input框绑定事件。一、基础概念在Vue.js中,input框绑定事件指的是将输入框的值绑定到Vue实例的数据对象中,从而实现输入和响应的双向绑定。在Vue.j


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor
