表单验证
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form id ='f1' action="https://www.baidu.com" method="get"> <div><input name="n1" type="text"></div> <div><input name="n2" type="password"></div> <div><input name="n3" type="text"></div> <div><input name="n4" type="text"></div> <div><input name="n5" type="text"></div> <input type="submit" value="提交"> </form> <script src="jquery1.9.js"></script> <script> $(':submit').click(function () { $('#f1').find('input[type="text"]','input[type="password"]').each(function () { var v=$(this).val(); console.log(1) if(v.length<=0){ return false; } }); console.log("haha"); return false; }); </script> </body> </html>