Loading

兼容IE8及其他浏览器的回车事件

//阻止默认浏览器行为
function stopDefault(e) {    
        //如果提供了事件对象,则这是一个非IE浏览器     
        if(e && e.preventDefault) {    
          //阻止默认浏览器动作(W3C)    
          e.preventDefault();    
        } else {    
          //IE中阻止函数器默认动作的方式     
          window.event.returnValue = false;     
        }    
        return false;    
    }


$(document).keydown(function (event) {
    if (event.keyCode == 13) {
        //回车执行函数
        stopDefault(event)
    }
});

 

posted @ 2017-06-13 17:14  冯叶青  阅读(832)  评论(0编辑  收藏  举报