登陆回车(Enter)事件

版权声明:版权: https://blog.csdn.net/sinat_41661009/article/details/80816322
function keyLogin(event){

    //谷歌能识别event,火狐识别不了,所以增加了这一句,chrome浏览器可以直接支持event.keyCode  
    var theEvent = window.event || arguments.callee.caller.arguments[0];   

    var key = theEvent.keyCode; 

    if (key==13) {//回车键的键值为13

        var toClick=document.getElementById("btn");
        
        toClick.click();  //调用登录按钮的登录事件

    }

}
在表单form提交的同时  需要在form标签中添加 onkeydown属性
<form onkeydown='keyLogin()'></form>
最后在form方法中调用 keyLogin() 就可以了。

猜你喜欢

转载自blog.csdn.net/sinat_41661009/article/details/80816322