夺命雷公狗jquery---27默认行为,判断用户名不能为空
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="js/jquery.js"></script> <script> $(function(){ $('#submit').bind('click',function(){ if($('#username').val() == ''){ //阻止默认行为 alert('用户名不能为空'); event.preventDefault(); } }); }); </script> </head> <body> <form action="1.php" method="post"> <input type="text" id="username" /> <hr /> <input type="submit" name="submit" id="submit" value="提交" /> </form> </body> </html>