我正在使用引导模态。问题是当我尝试着重于文本区域时,模态消失了。

这是我的代码:

<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                 <h4 class="modal-title" id="myModalLabel">Secret #<?php echo $counter; ?></h4>
            </div>
            <div class="modal-body">
                <div class="modal-body">
                    <form method="post" action="">
                        <div class="form-group">
                            <textarea id="comment" name="comment" class="form-control" rows="2"></textarea>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                            <button name="comment" type="submit" class="btn btn-primary">Comment</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

最佳答案

因此,我已通过防止触发注释框的事件来解决此问题:

    $( ".modal form #comment" ).click(function( event ) {
      event.stopPropagation();

    });

09-15 13:10