隐藏方法上的Bootsrap Modal不会触发

时间:2016-11-16 15:40:01

标签: javascript jquery html twitter-bootstrap

模态:

<div id="modalRelease" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Revision Release</h4>
            </div>
            <div class="modal-body">
                <div style="text-align:center; color:red;"><p>You are about to release to the next Revision level.</p></div>
                <div style="text-align:center;"><p>Description Required:</p></div>
                <div>
                    <textarea name="RevisionDescription" id="RevisionDescription" class="form-control" placeholer="Description..." data-rule-required="true" data-msg-required="Please enter a description."></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <div class="alert alert-danger" id="RevisionSubmitError">A description is required.</div>
                <div>
                    <button type="button" class="btn btn-success" id="ReleaseSubmit">
                        <i class="fa fa-save"></i> Submit
                    </button>
                    <button type="button" class="btn btn-warning" data-dismiss="modal">
                        <i class="fa fa-remove"></i> Cancel
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

按钮单击捕获事件:

   $(document).on("click", "#ReleaseSubmit", function (event) {
        if ($.trim($('#RevisionDescription').val()) == "") {
            $("#RevisionSubmitError").fadeIn("slow", function () { });
        }
        else {
            submitForm('release')
        }
    });

然后,尝试捕获Hide事件,以便在用户关闭然后重新打开模式时仍然无法显示错误消息,但这不会触发:

$('#modalRelease').on('hide.bs.modal', function () {
    $('#RevisionSubmitError').hide()
})

其中'RevisionSubmitError'是模态体内的div。 div永远不会被隐藏。我也尝试过hidden.bs.modal。

使用Bootstrap v3.3.6

1 个答案:

答案 0 :(得分:1)

在表单提交后,您是否在模式上调用了.modal('hide')?这就是需要为hide.bs.modal&#39;解雇