JavaScript添加回车响应

Posted by Dapenson on May 29, 2020

JavaScript添加回车响应

在js文件中或</script> </script>标签中添加如下代码段

    document.onkeydown = function (e) { // 回车提交表单
        // 兼容FF和IE和Opera
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
        if (code == 13) {
            your_function();
        }
    }