js实现按回车键登录_ico
//按回车键实现登录
$(document).keydown(function (event) {
if (event.keyCode == 13) {
$("#loginadmin").click();
}
});
html代码块

 <button type="button" id="loginadmin" class="frm-submit">登录<i class="fa fa-arrow-circle-right"></i></button>

完整JS代码

 //按回车键实现登录
    $(document).keydown(function (event) {
        if (event.keyCode == 13) {
            $("#loginadmin").click();
        }
    });


$('#loginadmin').click(function () {


    $.ajax({
        type: "POST",
        url: "/ptzjAdmin/login",
        data: {
            "admin_name": $("#adminname").val(),
            "password": $("#psw").val(),

        },
        dataType: "json",
        success: function (data) {

            if (data.result == "0") {
                layer.alert("登录成功!", {icon: 1, closeBtn: 2});
                window.location.href = "/ptzjAdmin/index";

            } else if (data.result == "1") {
                alert("用户名不能为空");
            } else if (data.result == "2") {
                alert("密码不能为空");
            } else if (data.result == "3") {
                layer.alert("用户名或者密码不对", {icon: 2, closeBtn: 2});
            }
        }
    });
});