This article shares with you the code for using jquery to implement form verification and prevent illegal submissions. The idea is very good. I recommend it to my friends for reference.
The code detects the length filled in the textarea. If it is not filled in, it will prompt that it needs to be filled in again. If it is less than 15 characters, it will prompt that it needs to be longer than 15 characters. If it is successful, it will display the filled-in suggestions.
<script type="text/javascript"> //jQuery代码 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; } } </script> <form action="" method="post" onSubmit="return confirm();" > <textarea id="advice" rows="20" cols="50"placeholder="Give us some advice?"></textarea> <input type="submit"value="Thank you"/> </form>
>Key points
1. There must be onSubmit="return confirm();" The word return is indispensable.
2. Complete web page structure by yourself.
The above is the entire content of this article, I hope you all like it.
For more related tutorials, please visit JavaScript Tutorial