好吧,我想通过按Enter键但不显示提交按钮来提交表单.如果可能的话,我不想进入JavaScript,因为我希望所有浏览器都可以工作(我知道的唯一JS方式是事件).
现在表单看起来像这样:
<form name="loginBox" target="#here" method="post">
<input name="username" type="text" /><br />
<input name="password" type="password" />
<input type="submit" style="height: 0px; width: 0px; border: none; padding: 0px;" hidefocus="true" />
</form>
Run Code Online (Sandbox Code Playgroud)
哪个效果很好.当用户按下Enter键时,提交按钮会起作用,并且该按钮不会显示在Firefox,IE,Safari,Opera和Chrome中.但是,我仍然不喜欢这个解决方案,因为很难知道它是否适用于所有浏览器的所有平台.
有谁能建议更好的方法?或者这是否与它一样好?
如果表单已提交但未通过任何特定按钮提交,例如
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)