WEB开发中,如果页面中只有一个input元素且type=”text“,在该input元素的输入框中按回车(注:此时并没有写对应的onkeydown等事件处理),则浏览器会默认提交表单,请看如下代码:
<html>
<head>
<title>页面中只有一个input元素时默认提交表单</title>
</head>
<body>
<form action="XXX" name="myform" method="get">
<input name="contenta" type="text" value="Enter To Submit" /></br>
</form>
</body>
</html>
禁止的方式最好采用,禁用form的onsubmit事件,使用JS进行提交
<html>
<head>
<title>页面中只有一个input元素时默认提交表单</title>
</head>
<body>
<form οnsubmit="return false;"action="XXX" name="myform" method="get">
<input name="contenta" type="text" value="Enter To Submit" /></br>
</form>
</body>
</html>
function update() { document.forms[0].action="${contextPath}UpdateAction.action"; document.forms[0].submit(); }