相关疑难解决方法(0)

为什么输入时按Enter键会提交带有单个输入字段的表单

为什么<form>单个<input>字段的a会在用户输入值并按下时重新加载表单Enter,如果?中有2个或更多字段则不会<form>.

我写了一个简单的页面来测试这种古怪.

如果您在第二个表单中输入一个值并按Enter键,您将看到它重新加载传递输入值的页面,就像您调用了一样GET.为什么?我该如何避免呢?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>testFormEnter</title>
</head>
<body>
<form>
  <input type="text" name="partid2" id="partid2" />
  <input type="text" name="partdesc" id="partdesc"  />
</form>
  <p>2 field form works fine</p>
<form>
<input type="text" name="partid" id="partid"  />
</form>
<p>One field form reloads page when you press the Enter key why</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript forms

74
推荐指数
5
解决办法
3万
查看次数

标签 统计

forms ×1

html ×1

javascript ×1