微信小程序表单验证错误提示

表单验证 点击确认发布不能为空错误提示

以下是效果图:


代码如下:

WXML:

[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. <view class="ad_popError" wx:if="{{popErrorMsg}}">{{popErrorMsg}}</view>  
  2. <view class="ad_popFt">  
  3. <form bindsubmit="goDetail" >  
  4.       <textarea class="ad_popArea" bindinput="commentTxtFn" focus="{{isPopOpen}}" placeholder="请输入留言内容"  placeholder-style="color:#cccccc;" name="textarea" />  
  5.   <view class="ad_popCout">  
  6.     <text class="one_star">你还可以输入</text>  
  7.     <text class="one_stars {{!!tips?'danger':''}}">{{commentTxtCount}}</text>  
  8.     <text class="one_star"></text>  
  9.   </view>  
  10.   <button class="informBtn" form-type="submit">确认发布</button>  
  11. </form>  
  12. </view>  


WXSS:

[css]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. page{background#f4f4f4;}  
  2. .ad_popHd{height76rpx; line-height76rpx; font-size32rpx;text-aligncenterborder-bottom1px solid #cdd1cdpadding0 20rpx;color#202120;}  
  3. .ad_popFt{ margin20rpx ; margin-top50rpx;}  
  4. .ad_popArea{ width708rpx;  height:400rpx;font-size:30rpx;padding20rpx; box-sizing: border-box; -webkit-box-sizing: border-box; line-height40rpx; color#333background#fff; }  
  5. .ad_popCout{ color#969899font-size24rpx; text-alignrightline-height58rpx; padding0 20rpx;}  
  6. .informBtn{background#09bb07;color#fff;font-size34rpx; margin-top38rpx;height88rpx;}  
  7. .one_stars{color#999;}  
  8. .one_star{font-size20rpx;color#999;}  
  9. .danger{ color#f64400;}  
  10. .ad_popError{ background#de352dcolor#fffheight58rpx; line-height58rpx; font-size24rpx; text-aligncenter;  positionabsolute; left: 0; top: 0width100%z-index:3;}  

JS:

[javascript]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. // pages/informLeaveMsg/informLeaveMsg.js  
  2. Page({  
  3.   
  4.   /** 
  5.    * 页面的初始数据 
  6.    */  
  7.   data: {  
  8.       
  9.   },  
  10.   //确认发布  
  11.   goDetail:function(e){  
  12.     setTimeout(()=>{  
  13.       var subValue = e.detail.value.textarea  
  14.       console.log(subValue)  
  15.       if (subValue == null || subValue == "") {  
  16.         console.log("不能为空")  
  17.         this.setData(  
  18.           { popErrorMsg: "发布的留言内容不能为空" }  
  19.         );   
  20.         this.ohShitfadeOut();   
  21.         return;        
  22.       }  
  23.        
  24.     },100)  
  25.      
  26.   },  
  27.   
  28.   ohShitfadeOut() {  
  29.     var fadeOutTimeout = setTimeout(() => {  
  30.       this.setData({ popErrorMsg: '' });  
  31.       clearTimeout(fadeOutTimeout);  
  32.     }, 3000);  
  33.   },  
  34.   
  35. })  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值