点击回车事件(登录)

//增加点击回车事件
        $(document).keypress(function(e) {
            var eCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
            //eCode等于13代表回车事件
            if (eCode == 13){
                //ajax提交表单,若成功跳转页面,不成功提示输入的账号密码错误!
                $.ajax({
                    type : 'post',
                    dataType : 'json',
                    url : basePath + '/login/verify',
                    data : $('#loginForm').serialize(),
                    success: function (result) {
                        if(result.status == 200){
                            //登录成功则跳转到首页
                            location.href = basePath + '/index';
                        }else {
                            alert('用户名或账号错误');
                        }
                    }
                });

            }
        });

猜你喜欢

转载自www.cnblogs.com/lazyli/p/10973244.html