提交表单仅在firefox浏览器中不起作用

时间:2020-05-01 10:56:52

标签: javascript jquery firefox

我正在从Bootstrap模式提交表单,而我仅对Firefox有问题,这是非常简单的代码,

$('#confirmBtn').click(function(e){
    e.preventDefault();
    $('#s-form').submit();
  });

从模式中调用

<div class="modal" tabindex="-1" role="dialog" id="sipChannel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title"><strong>Updating SIP Channel</strong></h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <p>Please confirm we are updating <%= @customer.company_name %> SIP channels from x to y,
           this will affect your billing and will take affect within the next few minutes.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
        <button type="button" class="btn btn-primary" type="submit" id="confirmBtn">Confirm</button>
      </div>
    </div>
  </div>
</div>

表格

  <div style="" class="col-md-5 offset-md-2 custom-form">
    <%= form_for @changeset, Routes.customer_path(@conn, :update_info, @customer.id), [id: "s-form", as: :customer], fn f -> %>
      <h6>Channels:</h6>

      <div class="input-group input-group--t4-xl">
        <%=
          number_input(f, :channels,
            class: "custom-text-field form-control form-control-lg",
            style: "",
            disabled: true,
            max: (@customer.channels || 1) * 2,
            min: 1,
            id: "s-number"
          )
        %>

        <div class="input-group-append" id="cancel-sip">
          <button class="btn btn-outline-secondary" id="edit-sip">
            Edit 
          </button>
        </div>
      </div>
    <% end %>

如果我将console.log("...")放入我的jquery函数中,我可以通过单击按钮来调用该函数,但是Firefox忽略了submit,那么我该如何解决呢?

1 个答案:

答案 0 :(得分:1)

为什么不只是将按钮放在表单内而不使用jQuery? 或在其中添加form="s-form"

如果不是,则应为type = button,这样就无需在click事件上使用preventDefault。

否则,如果需要确认,请使用

$('#s-form').on("submit",function(e) {
  if (!confirm("Are you sure")) e.preventDefault();
});