微信小程序中表单验证错误提示的效果呈现

why 104 2024-08-23

这篇文章主要为大家详细介绍了微信小程序表单验证错误提示效果,点击确认发布不能为空错误提示,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

微信小程序表单验证,点击确认发布不能为空错误提示,具体内容如下

以下是效果图:

代码如下:

WXML:


1

2

3

4

5

6

7

8

9

10

11

12

<view class="ad_popError" wx:if="{{popErrorMsg}}">{{popErrorMsg}}</view>

<view class="ad_popFt">

<form bindsubmit="goDetail" >

  <textarea class="ad_popArea" bindinput="commentTxtFn" focus="{{isPopOpen}}" placeholder="请输入留言内容" placeholder-style="color:#cccccc;" name="textarea" />

 <view class="ad_popCout">

 <text class="one_star">你还可以输入</text>

 <text class="one_stars {{!!tips?&#39;danger&#39;:&#39;&#39;}}">{{commentTxtCount}}</text>

 <text class="one_star">字</text>

 </view>

 <button class="informBtn" form-type="submit">确认发布</button>

</form>

</view>


WXSS:


1

2

3

4

5

6

7

8

9

10

page{background: #f4f4f4;}

.ad_popHd{height: 76rpx; line-height: 76rpx; font-size: 32rpx;text-align: center; border-bottom: 1px solid #cdd1cd; padding: 0 20rpx;color: #202120;}

.ad_popFt{ margin: 20rpx ; margin-top: 50rpx;}

.ad_popArea{ width: 708rpx; height:400rpx;font-size:30rpx;padding: 20rpx; box-sizing: border-box; -webkit-box-sizing: border-box; line-height: 40rpx; color: #333; background: #fff; }

.ad_popCout{ color: #969899; font-size: 24rpx; text-align: right; line-height: 58rpx; padding: 0 20rpx;}

.informBtn{background: #09bb07;color: #fff;font-size: 34rpx; margin-top: 38rpx;height: 88rpx;}

.one_stars{color: #999;}

.one_star{font-size: 20rpx;color: #999;}

.danger{ color: #f64400;}

.ad_popError{ background: #de352d; color: #fff; height: 58rpx; line-height: 58rpx; font-size: 24rpx; text-align: center; position: absolute; left: 0; top: 0; width: 100%; z-index:3;}


JS:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

// pages/informLeaveMsg/informLeaveMsg.js

Page({

  

 /**

 * 页面的初始数据

 */

 data: {

   

 },

 //确认发布

 goDetail:function(e){

 setTimeout(()=>{

  var subValue = e.detail.value.textarea

  console.log(subValue)

  if (subValue == null || subValue == "") {

  console.log("不能为空")

  this.setData(

   { popErrorMsg: "发布的留言内容不能为空" }

  );

  this.ohShitfadeOut();

  return

  }

   

 },100)

   

 },

  

 ohShitfadeOut() {

 var fadeOutTimeout = setTimeout(() => {

  this.setData({ popErrorMsg: &#39;&#39; });

  clearTimeout(fadeOutTimeout);

 }, 3000);

 },

  

})


以上就是本文的全部内容,希望对大家的学习有所帮助。


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Nodejs 助力微信小程序密码加密的开发实现方法
下一篇:微信小程序搭建与登录失败问题的解决途径
相关文章

 发表评论

暂时没有评论,来抢沙发吧~