<form action="" class="idxform1" onsubmit="return formyz(‘j_name‘,‘j_phone‘,‘j_em‘,‘j_content‘,‘j_code‘)"> <div class="ipt1 "><span>姓名</span><input type="text" class="j_name"></div> <div class="ipt1 "><span>电话</span><input type="text" class="j_phone"></div> <div class="ipt1 "><span>邮箱</span><input type="text" class="j_em"></div> <div class="ipt2"> <span>内容</span> <textarea class="j_content"></textarea> </div> <div class="yzm"> <input type="text" class="j_code" placeholder="验证码"> <div class="zzyzm"></div> </div> <input class="idxtj" type="submit" value="提 交"> </form> <script type="text/javascript"> //联系我们表单验证 function formyz(name,phone,em,content,code){ var name=$("."+name); var phone=$("."+phone); var em=$("."+em); var content=$("."+content); var code=$("."+code); if(name.val()==""){ name.parent(".ipt1").css({"border":"1px solid #3598db"}); name.val(""); name.focus(); return false; } if(!(/^1\d{10}$/.test(phone.val()))){ phone.parent(".ipt1").css({"border":"1px solid #3598db"}); phone.val(""); phone.focus(); return false; } if(!(/^(\w-*\.*)[email protected](\w-?)+(\.\w{2,})+$/.test(em.val()))){ em.parent(".ipt1").css({"border":"1px solid #3598db"}); em.val(""); em.focus(); return false; } if(code.val()==""){ code.css({"border":"1px solid #3598db"}); code.val(""); code.focus(); return false; } else{ return true; } } </script>
原文地址:https://www.cnblogs.com/bigbigxiao/p/10031595.html
时间: 2024-11-08 04:21:02