我有一张包含以下内容的表单:
echo"<textarea name='pb' required></textarea>";
echo"<button name='bt'>button1</button>";
echo"<button name='bt'>button2</button>";
echo"<button name='bt'>button3</button>";
echo"<button name='bt'>button4</button>";
echo"<input type=submit name='submit' value='Submit'>";
&#13;
正如您在我的代码中看到的那样,textarea是必需的,但我有很多按钮。我只想在按下提交按钮时显示需要textarea的消息,但是当我点击其他按钮时,该消息不会出现。
答案 0 :(得分:0)
将type="button"
添加到按钮应该可以解决问题:
<button name="bt" type="button">button</button>
有关按钮的更多信息,请参阅MDN:https://developer.mozilla.org/nl/docs/Web/HTML/Element/button
submit
:该按钮将表单数据提交给服务器。 如果未指定属性,或者属性动态更改为空值或无效值,则为默认值。
button
:该按钮没有默认行为。它可以具有与元素事件关联的客户端脚本,这些脚本在事件发生时触发。
答案 1 :(得分:0)
Phorturin是正确的。正如this question,按钮中所述,默认提交类型为(see the html spec for more info.)如果您将类型设置为按钮,则他们将无法提交您的表单。