登陆按钮绑定回车事件

时间:2022-10-17 19:42:55

<%= form_tag sessions_path, :remote => true, style: 'z-index:999999999999px;', class: 'hd' do %>
        <p><h1>登录</h1><a href="/forget">忘记密码</a> | <a href="/supplier_applies/free#new_supplier_apply" class="font-red">申请试用 &gt; </a></p>

        <p class="form" id="login-name">
          <%= text_field_tag :login, params[:login], class: "txt", id: "account-place" %>
        </p>

        <p class="form" id="login-pswd">
          <%= password_field_tag :password, nil, id: "password-place" %>
        </p>

        <p><a class="btn-login">登录</a></p>
        <input id="hidden_login_submit" style="display:none" type="submit"/>
        <% end %>

 

<script>

/*全页面回车*/

document.onkeydown = function(){
    if(event.keyCode == "13"){
        document.getElementById("hidden_login_submit").click();
    }
  }

/*input输入框回车*/

$("#login-name, #login-pswd").keypress(function(event) {

    if ( event.which == 13 ) {
        $(".hd").submit();
    }

});

</script>