Bootstrap 3 模态形式不触发 jQuery .submit()

Bootstrap 3 modal form not triggering jQuery .submit()

我正在尝试获取 Bootstrap 3 模态形式以在 jQuery 中触发 form.submit(),但无论我尝试什么,我都无法触发它。

<div class="modal fade" id="modal-signup" tabindex="-1" role="dialog" aria-labelledby="modal-signup" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Sign up</h4>
      </div>
      <div class="modal-body">
        <form role="form" action="/"  id="modal-signup-form" >
          <div class="form-group">
            <input type="email" class="form-control input-lg" placeholder="email">
          </div>
          <div class="form-group">
            <input type="password" class="form-control input-lg" placeholder="password">
          </div>
          <div class="form-group">
            <input type="password" class="form-control input-lg" placeholder="confirm">
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <p>Already have account ? <a href="#" data-toggle="modal" data-target="#modal-signin">Sign in here.</a></p>
        <input type="submit" class="btn btn-success btn-block btn-lg" value="Sign up">
      </div>
    </div>
  </div>
</div>

和 JS

$("#modal-signup-form").submit(function( event ) {

event.preventDefault();

  alert("made it");

    $.ajax({
        type: "POST",
        url: "adduser.php",
        data: $('form.adduser_model').serialize(),
        success: function (msg) {

            $("#thanks").html(msg)
            $("form.noteform").modal('hide');
        },
        error: function () {
            alert("failure");
        }
    });
    return false;
});

我创建了一个 fiddle...

http://jsfiddle.net/menriquez/sreco3jt/

如果您在模型表单中点击 "Sign Up" 和 "Sign Up",我希望事件触发并看到警报,但它没有。

这是因为提交按钮不在 #modal-signup-form 表单元素内。

要么将按钮添加到 <form> 内部,要么添加事件处理程序以在单击按钮时触发提交:

$(document).on('click', '#modal-signup-form-submit', function (e) {
    $('#modal-signup-form').submit();
});

Updated Example

您必须在关闭表单标记之前添加以下提交按钮代码。

<input type="submit" class="btn btn-success btn-block btn-lg" value="Sign up">

JS Fiddle