jquery实现表单验证并阻止非法提交

前端之家收集整理的这篇文章主要介绍了jquery实现表单验证并阻止非法提交前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

代码检测textarea内填写的长度,未填写时提示需要重新填写,少于15字符时提示需要长于15字符,成功时显示所填写建议。

代码 function confirm() {   if($("#advice").val().length == 0) {   alert("We can't see your advice. Maybe you should fill the form first.");   $("#advice").focus();   return false; } else if($("#advice").val().length <= 15) {   alert("Your advice should longer than 15 letters.");   $("#advice").focus();   return false; } else {   alert("Thank you for your advice! You will get out reply in 24 hours for advice:\n"+$("#advice").val());   return true; } }