兼容IE与firefox火狐的回车事件(js与jquery)


javascript 兼容IE与firefox火狐的回车事件
复制代码 代码如下:

<script>
document.onkeydown=function(event)
{
e = event ? event :(window.event ? window.event : null);
if(e.keyCode==13){
//执行的方法
alert('回车检测到了');
}
}
</script>


jquery 兼容IE与firefox火狐的回车事件
复制代码 代码如下:

$(document).ready(function(){
$("按下回车的控件").keydown(function(e){
var curKey = e.which;
if(curKey == 13){
$("#回车事件按钮控件").click();
return false;
}
});
});

这个问题解决了,如果有更好的解决方案也希望拿出来一起分享一下。
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3