基于jQuery实现表单提交验证

前端技术 2023/09/07 JavaScript

html表单代码:

&&!/.+@.+\\.[a-zA-Z]{2,4}$/.test(this.value))){
                        var errorMsg = \'请输入正确的E-mail地址\';
                        $parent.append(\'<span class=\"formtips onError\">\'+errorMsg+\'</span>\');
                    }else{
                        var okMsg = \'输入正确\';
                        $parent.append(\'<span class=\"formtips onSuccess\">\'+okMsg+\'</span>\');
                    }
                }
            });
            $(\"form :input\").focus(function(){
                var $parent = $(this).parent();
                $parent.find(\".formtips\").remove();
            });
            $(\"#send\").click(function(){
               var $parent = $(this).parent().parent();
               $parent.find(\".formtips\").remove();
               $(\"form .required:input\").trigger(\'blur\');
               var numError = $(\'form .onError\').length;
               if(numError){
                  return false;
               }
            });
            $(\"#res\").click(function(){
                var $parent = $(this).parent().parent();
                $parent.find(\".formtips\").remove();
            });
        });

代码很简单,也很易懂,小伙伴们直接拿走用吧,这里就不详细说明了。

本文地址:https://www.stayed.cn/item/19568

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。