如果单击按钮(提交的输入类型),则忽略表单中的必需输入
Ignore required inputs in a form if a button (input type of submit) is clicked
我有一个表单有两个按钮(提交的两种输入类型)。
一个按钮比另一个按钮需要更多的输入。
我怎么能按下不需要某些输入的按钮而不被停止,因为它说需要的输入是空的(但实际上只有另一个按钮需要它们)。
谢谢,非常感谢您的帮助!
阿尔
编辑代码:
我写了一小段代码来反映我的问题。让我们假设在按下第一个按钮时您需要所有输入。当您按下第二个按钮时,您只需要第二个输入。在这种情况下,我如何忽略第一个必需的输入?
<form id="formID" action="processForm.php" method="post">
<input id="firstInput" name="input1" placeholder="Amount" required>
<input id="secondInput" name="input2" placeholder="Amount2" required>
<input type="submit" value="firstInput" alt="firstButton">
<input type="submit" value="secondInput" alt="secondButton">
</form>
我写了一小段代码来反映我的问题。
好的,所以我可以使用以下代码完成此操作:
<form id="formID" action="processForm.php" method="post">
<input id="firstInput" name="input1" placeholder="Amount" required>
<input id="secondInput" name="input2" placeholder="Amount2" required>
<input id="firstButtonClick" type="submit" value="firstInput" alt="firstButton">
<input id="secondButtonClick" type="submit" value="secondInput" alt="secondButton">
</form>
$(document).ready(function() {
$("#secondButtonClick").click(function() {
document.getElementById("secondInput").required = false;
});
我有一个表单有两个按钮(提交的两种输入类型)。
一个按钮比另一个按钮需要更多的输入。
我怎么能按下不需要某些输入的按钮而不被停止,因为它说需要的输入是空的(但实际上只有另一个按钮需要它们)。
谢谢,非常感谢您的帮助! 阿尔
编辑代码: 我写了一小段代码来反映我的问题。让我们假设在按下第一个按钮时您需要所有输入。当您按下第二个按钮时,您只需要第二个输入。在这种情况下,我如何忽略第一个必需的输入?
<form id="formID" action="processForm.php" method="post">
<input id="firstInput" name="input1" placeholder="Amount" required>
<input id="secondInput" name="input2" placeholder="Amount2" required>
<input type="submit" value="firstInput" alt="firstButton">
<input type="submit" value="secondInput" alt="secondButton">
</form>
我写了一小段代码来反映我的问题。
好的,所以我可以使用以下代码完成此操作:
<form id="formID" action="processForm.php" method="post">
<input id="firstInput" name="input1" placeholder="Amount" required>
<input id="secondInput" name="input2" placeholder="Amount2" required>
<input id="firstButtonClick" type="submit" value="firstInput" alt="firstButton">
<input id="secondButtonClick" type="submit" value="secondInput" alt="secondButton">
</form>
$(document).ready(function() {
$("#secondButtonClick").click(function() {
document.getElementById("secondInput").required = false;
});