1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > jQuery实现表单提交验证

jQuery实现表单提交验证

时间:2021-02-21 15:38:05

相关推荐

jQuery实现表单提交验证

jQuery代码: $(function(){ $(“form :input.required”).each(function(){ var $required = ("∗");//(" *"); //("∗");//(this).parent().append($required); //追加到文档中 (this).parent().prepend((this).parent().prepend((this).parent().prepend(required); }); $(‘form :input’).blur(function(){ var $parent = (this).parent();if((this).parent(); if((this).parent();if((this).is(’#username’)){ if(this.value==""||this.value.length<6){ var errorMsg = ‘请输入至少6位的用户名’; $parent.append(’ ‘+errorMsg+’’); }else{ var okMsg = ‘输入正确’; KaTeX parse error: Double superscript at position 17: …arent.append(' '̲+okMsg+''); } }…(this).is(’#email’)){ if(this.value==""||(this.value!=""&&!/.+@.+.[a-zA-Z]{2,4}$/.test(this.value))){ var errorMsg = ‘请输入正确的E-mail地址’; $parent.append(’ ‘+errorMsg+’’); }else{ var okMsg = ‘输入正确’; $parent.append(’ ‘+okMsg+’’); } } }); $(“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(); }); });

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。