夺命雷公狗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>

 

posted @ 2015-10-27 16:07  夺命雷公狗  阅读(153)  评论(0编辑  收藏  举报