JSFiddle - React, Tailwind, and code Playground

by bluthcy

HTML

<section>
  <h2>表单回车自动提交案例一</h2>
  <p>表单中有一个submit按钮时,在文本输入框中回车就会提交表单</p>
  <form method="post" action="">
    <input type="text" />
    <input type="submit" value="提交" />
  </form>
</section>
<section>
  <h2>表单回车自动提交案例二</h2>
  <p>表单中如果有且只有一个文本输入框,在文本输入框中回车会提交表单</p>
  <form method="post" action="">
    <input type="text" />
  </form>
</section>

CSS

section p {
  font-weight: bold;
  color: #888;
  font-style: italic;
}

JavaScript

$('form').submit(function(e) {
  alert('submited');
  return false;
});