【问题标题】:Form button, without type submit, submits form表单按钮,无类型提交,提交表单
【发布时间】:2019-03-21 06:08:15
【问题描述】:

我知道按钮上的 type="submit" 和输入一样。

这里的问题是:如果我有一个表单,没有任何提交按钮/输入,为什么会触发提交?

<form method="post" action="lf-p1-02a.html">
    <div class="d-flex justify-content-center flex-wrap buttonCheck multiButtonCheck">
        <button class="col-md-6 formButton bigButton">
            <span>Button 1</span>
        </button>
        <button class="col-md-6 formButton bigButton">
            <span>Button 2</span>
        </button>
        <button class="col-md-6 formButton bigButton">
            <span>Button 3</span>
        </button>
        <button class="col-md-6 formButton bigButton">
            <span>Button 4</span>
        </button>
    </div>
    <div class="d-flex justify-content-center formFooter">
        <button class="mainBtn">Continue</button>
    </div>
</form>

小提琴:http://jsfiddle.net/36zsa1t8/(我知道没有任何样式)。

表单中的“继续”按钮实际上是提交它,进入下一页。

代码中没有 JavaScript。

知道为什么会这样吗?

【问题讨论】:

    标签: html forms button submit


    【解决方案1】:

    正如this answer 中所解释的,对于大多数浏览器,button 的默认typesubmit

    【讨论】:

    • 谢谢你,我没有意识到这一点。很高兴知道更多!
    【解决方案2】:

    &lt;Button&gt;标签改为&lt;input type="button" value="Button"&gt;

    <input type="button" class="col-md-6 formButton bigButton" value="Button">
                <span>Utilizo el listado mensual de<br> consumo o límite preconcedido</span>
            </input>
    

    更新JSFiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-09
      • 1970-01-01
      • 2014-03-23
      • 1970-01-01
      • 2013-01-09
      • 2015-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多