![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta charset="UTF-8"/> <title>Title</title> <style> .error{ color: red; } </style> </head> <body> <form id="ff" method="post"> <div><input type="text"/></div> <div><input type="password"/></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-1.12.4.js"></script> <script> $(':submit').click(function () { $('.error').remove() var flag = true; $('#ff').find('input[type="text"],input[type="password"]').each(function () { var tag = $(this).val(); if (tag.length <= 0) { flag = false; var v= document.createElement('span'); v.innerHTML = '必填'; v.className='error'; $(this).after(v) return false // 只提示第一个 return false } }) return flag; }) </script> </body> </html>