<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .active{ color:red; } </style> </head> <body> <form action="s4.html" method="post" id="f1"> <div> <input type="text"> </div> <div> <input type="text"> </div> <div> <input type="text"> </div> <div> <input type="text"> </div> <div> <input type="submit" value="提交"> </div> </form> <script src="../jquery-2.12.4.js"></script> <script> $('#f1').find(':submit').click(function () { var tag = true; $('.active').remove(); $('#f1').find(':text').each(function () { if($(this).val().length<=0){ tag = false; span = document.createElement('span'); span.innerText = '必填'; $(span).addClass('active'); $(this).after(span); } }); return tag; }) </script> </body> </html>