如果表单已提交但未通过任何特定按钮提交,例如
HTMLFormElement.submit()在JS中使用浏览器应该如何确定多个提交按钮中的哪一个(如果有的话)用作按下的按钮?
这在两个层面上很重要:
onclick附加到提交按钮的事件处理程序到目前为止,我的实验表明:
标准说什么?
如果它会有所帮助,这是我的测试代码(PHP仅与我的测试方法相关,而不是我的问题本身)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
<h1>Get</h1>
<dl>
<?php foreach ($_GET as $k => $v) echo "<dt>$k</dt><dd>$v</dd>"; ?>
</dl>
<h1>Post</h1>
<dl>
<?php foreach ($_POST as $k => $v) echo "<dt>$k</dt><dd>$v</dd>"; ?>
</dl>
<form name="theForm" method="<?php echo isset($_GET['method']) ? $_GET['method'] : 'get'; ?>" action="<?php echo …Run Code Online (Sandbox Code Playgroud) 为什么<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)