如何禁用单击弹出窗口退出?

时间:2014-07-26 03:07:51

标签: javascript twitter-bootstrap

我在我的网站上创建了这个弹出框:

enter image description here

使用以下代码:

<div class="modal custom fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            <h4 class="modal-title" id="myModalLabel">Upload a Meme</h4>
        </div>
        <div class="modal-body">
            <div class="input-group">
                <input type="text" class="form-control" placeholder="Url: http://" id="urlInput">
                <input type="text" class="form-control" placeholder="Title" id="titleInput">
                <input id="saveComments" type="text" class="form-control" placeholder="Comments">
                <input type="text" class="form-control" placeholder="Tags" id="tagInput">
            </div>
            <br>
            <h4>&nbsp;Rate It:</h4>
            <div class="rating pull-left">
                <input type="radio" id="stars5" name="rating" value="5" /><label for="stars5" title="Rocks!">5 stars</label>
                <input type="radio" id="stars4" name="rating" value="4" /><label for="stars4" title="Pretty good">4 stars</label>
                <input type="radio" id="stars3" name="rating" value="3" /><label for="stars3" title="Meh">3 stars</label>
                <input type="radio" id="stars2" name="rating" value="2" /><label for="stars2" title="Kinda bad">2 stars</label>
                <input type="radio" id="stars1" name="rating" value="1" /><label for="stars1" title="Sucks big time">1 star</label>
            </div>
        </div>

        <div class="modal-footer">
            <button type="button" class="btn btn-default cancel" data-dismiss="modal">Cancel</button>
            <button type="button" class="btn btn-default submit" id="saveSubmit"><b>Submit</b></button>
        </div>
    </div>
</div>

我有一个取消按钮和一个提交按钮。取消按钮退出弹出窗口,但用户也可以在上载窗口外单击退出。

如何防止在框外点击退出?

由于

1 个答案:

答案 0 :(得分:2)

尝试将这两个字符串添加到您的HTML元素中:data-backdrop="static"data-keyboard="false"

将数据背景设置为静态和数据键盘为false可能会解决您的问题。

请查看here。它会为您提供解决方案