且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

防止在按Enter键时提交表单

更新时间:2022-11-01 20:08:26

在不查找实际代码的情况下,这是我要怎么做的基本原理:

Without looking up the actual code, here's the basic theory behind how I'd do it:

在文档上定义一个事件处理程序,以按下一个键来调用函数.

Define an event handler on the document for a key being pressed to call a function.

如果触发事件的键是回车键,则为return false,否则为return true.

If the key that triggered the event is the enter/return key, return false, otherwise return true.

看来您已经找到了答案(以及执行此操作的一些代码),所以现在我的答案有些不必要了.

Looks like you already found the answer (as well as some code to do it), so my answer is somewhat unnecessary now.