简体   繁体   English

html 表单两个按钮只一个提交

[英]html form two buttons only one to submit

I have a form with two buttons.我有一个带有两个按钮的表单。 The save changes button is the submit button but the delete button should not submit once clicked.保存更改按钮是提交按钮,但删除按钮一旦单击就不应提交。 The delete button should open a modal and in the modal there are two more buttons, one to go back(close modal) and one to finalize the delete.删除按钮应该打开一个模态,并且在模态中还有两个按钮,一个是 go 返回(关闭模态),一个是完成删除。 My issue is that as soon as the delete button is clicked on, the form thinks I want to submit which I don't.我的问题是,一旦单击删除按钮,表单就会认为我想提交而我不想提交。 How could I get around this?我怎么能解决这个问题? Thank you谢谢

<form>
          <div class="mailing-address">
            <p>Mailing Address</p>
            <div class="form3">
              <span class="edit-mailing1">
                <span>
                  <input type="text" required placeholder="Name" v-model="editFormData.name" />
                  <input type="text" required placeholder="Email" v-model="editFormData.email" />
                </span>
                <input type="text" required placeholder="Address Line 1" v-model="editFormData.address1" />
                <input type="text" placeholder="Address Line 2" v-model="editFormData.address2" />
              </span>
              <span class="edit-mailing2">
                <input type="text" required placeholder="Phone Number" v-model="editFormData.phone" />
                <input type="text" required placeholder="City" v-model="editFormData.city" />
                <span>
                  <SelectBox v-model="editFormData.state" />
                  <input type="text" required placeholder="Zip" v-model="editFormData.zip" />
                </span>
              </span>
            </div>
          </div>
          <div class="edit-section-footer">
            <CheckboxSlider v-model="editFormData.vip" :userId="editFormData.id" :reloadTable="reloadTable" />
            <span>
              <button class="button red" @click="isModalOpen = true">Delete User</button>
              <button class="button">Save Changes</button>
            </span>
          </div>
        </form>

在此处输入图像描述

You need to add type="submit" to the submit button, and add type="button" to the delete button.您需要将type="submit"添加到提交按钮,并将type="button"添加到删除按钮。

By default, a button inside a form will trigger a submit if there isn't a explicit submit button默认情况下,如果没有明确的提交按钮,表单内的按钮将触发提交

to prevent delete button from submit change it type to button insted of submit为了防止删除按钮提交,将其类型更改为提交的按钮

 <button onclick="somefunction()" type="button">Button</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM