介绍
小编给大家分享一下小程序如何实现表单验证,希望大家阅读完这篇文章之后都有所收获、下面让我们一起去探讨吧!
微信小程序表单验证,点击确认发布不能为空错误提示,具体内容如下
以下是效果图:
代码如下:
WXML:
& lt; view 类=癮d_popError",天气:如果=皗{popErrorMsg}}“在{{popErrorMsg}} & lt;/view>, & lt; view 类=癮d_popFt"祝辞, & lt; form  bindsubmit=癵oDetail",祝辞, & lt;才能textarea 类=癮d_popArea", bindinput=癱ommentTxtFn",专注=皗{isPopOpen}}“,占位符=扒胧淙肓粞阅谌荨?placeholder-style=把丈?# cccccc;“, name=皌extarea",/祝辞, ,& lt; view 类=癮d_popCout"祝辞, ,& lt; text 类=皁ne_star"在你还可以输入& lt;/text>, ,& lt; text 类=皁ne_stars {{! !建议? & # 39;危险# 39;:& # 39;& # 39;}}“在{{commentTxtCount}} & lt;/text>, ,& lt; text 类=皁ne_star"在字& lt;/text>, & lt;/view>大敌; ,& lt; button 类=癷nformBtn",表单类型=皊ubmit"祝辞确认发布& lt;/button>, 时间/form> & lt; & lt;/view>
wxs:
页面{背景:# f4f4f4;}, .ad_popHd{高度:76 rpx;,行高:,76 rpx;,字体大小:,32 rpx; text-align:,中心;,边界底部:,1 px solid # cdd1cd;,填充:,0,20 rpx;颜色:,# 202120;}, .ad_popFt{,保证金:20 rpx ;, margin-top:, 50 rpx;}, .ad_popArea{,宽度:708 rpx;,身高:400 rpx;字体大小:30 rpx;填充:,20 rpx;, box-sizing:, border-box;, -webkit-box-sizing:, border-box;,行高:,40 rpx;,颜色:,# 333;,背景:,# fff;,}, .ad_popCout{,颜色:# 969899;,字体大小:,24 rpx;, text-align:,,,行高:,58 rpx;,填充:,0,20 rpx;}, .informBtn{背景:# 09 bb07;颜色:,# fff;字体大小:,34 rpx;, margin-top:, 38 rpx;高度:,88 rpx;}, .one_stars{颜色:# 999;}, .one_star{字体大小:20 rpx;颜色:,# 999;}, .danger{,颜色:# f64400;}, .ad_popError{,背景:# de352d;,颜色:,# fff;,高度:,58 rpx;,行高:,58 rpx;,字体大小:,24 rpx;, text-align:,中心;,位置:,绝对的,,左:,0;,:,0;,宽度:,100%;,z - index: 3;}
JS:
//,页面/informLeaveMsg/informLeaveMsg.js 页面({, ,/* *大敌; ,*页面的初始数据, ,*/数据:,{大敌; ,, },大敌; ,//确认发布, goDetail:函数(e){大敌;; ,setTimeout(()=祝辞{, var 才能;subValue =, e.detail.value.textarea console.log才能(subValue), if 才能;(subValue ==, null | |, subValue ==,““), {, console.log才能(“不能为空“), ,this.setData(大敌; ,,{,popErrorMsg:“发布的留言内容不能为空,,}, ,,); this.ohShitfadeOut才能(),, 时间,,,返回; ,,}, ,, ,},100), ,, },大敌; , ,ohShitfadeOut (), {, ,var fadeOutTimeout =, setTimeout((),=祝辞,{, this.setData才能({,popErrorMsg: & # 39; & # 39;,}),, clearTimeout才能(fadeOutTimeout);, ,},3000);, },大敌; , })
看完了这篇文章,相信你对“小程序如何实现表单验证”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!