禁止enter回车键出发页面的onsubmit事件

<script>  
    //禁用enter键表单自动提交
    document.onkeydown = function(event) {  
        var target, code, tag;  
        if (!event) {  
            event = window.event; //针对IE浏览器  
            target = event.srcElement;  
            code = event.keyCode;  
            if (code == 13) {  
                tag = target.tagName;  
                if (tag == "TEXTAREA") { return true; }  
                else { return false; }  
            }  
        }  
        else {  
            target = event.target; //针对遵循w3c标准的浏览器,如Firefox、Chrome
            code = event.keyCode;  
            if (code == 13) {  
                tag = target.tagName;  
                if (tag == "INPUT") { return false; }  
                else { return true; }  
            }  
        }  
    };  
</script>

 

posted @ 2021-08-01 15:21  乱炖er  阅读(137)  评论(0编辑  收藏  举报