我有这个 HTML 表单:
<head>
<title>log in</title>
</head>
<body>
<form action="login.php" method="POST">
user name : <input type="text" name="user"> <br>
user pass : <input type="password" name="pass"> <br>
<input type="submit" value="submit">
</form>
</body>
我想使表单只能通过单击按钮提交 - 而不是通过按 Enter。我该怎么做?
最佳答案
有很多解决方案。这是最简单的一种:
<html>
<head>
<title>log in</title>
</head>
<body>
<form action="login.php" method="POST" onsubmit="return false;">
user name : <input type="text" name="user"> <br>
user pass : <input type="password" name="pass"> <br>
<input type="button" value="submit" onclick="this.parentNode.submit();">
</form>
</body>
</html>
关于javascript - 如何禁用表单中的输入按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10774621/