Javascript 引导删除模式内容问题

Javascript 引导删除模式内容问题,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,我知道这个问题是重复的,但我找不到与我的问题相匹配的答案。我正在使用boostrap 3.2.0,我有以下模式: <div class="modal fade popup" id="popupSelect"> <div class="modal-header"> <a class="close" data-dismiss="modal">&times;</a> <h4 class="modal-

我知道这个问题是重复的,但我找不到与我的问题相匹配的答案。我正在使用boostrap 3.2.0,我有以下模式:

<div class="modal fade popup" id="popupSelect">
    <div class="modal-header">
        <a class="close" data-dismiss="modal">&times;</a>
        <h4 class="modal-title">Select meal</h4>
    </div>
    <div class="modal-body-select">
        <div class="form-group">
            <label for="select" class="col-lg-2 control-label">Category</label>
            <div class="col-lg-10">
                <select name="selectCategory" class="form-control selectCategory"
                    id="selectCategory">
                    <option value="0">Select category</option>
                    <c:forEach items="${categories}" var="category">
                        <option value="${category.text}">${category.value}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <br>
        <div class="form-group">
            <label for="select" class="col-lg-2 control-label">Meal</label>
            <div class="col-lg-10">
                <select name="selectMeal" class="form-control idMeal" id="selectMeal">
                    <option value="0">Select meal</option>
                </select>
            </div>
        </div>
        <input type="hidden" value="-1" id="hSelectIndex"/>
    </div>

    <div class="modal-footer">
        <a href="" class="btn btn-warning buttons" data-dismiss="modal">Close</a>
        <input type="button" class="btn btn-warning buttons btnSaveChanges"
            value="Save Changes" />
    </div>
</div>
但它不起作用!我做错了什么?
每次按下选择按钮时,都会加载模式。每次模态被“隐藏”时,我都需要清除内容。

我不完全清楚您的问题是什么,但首先,在Bootstrap 3中,当模态被隐藏时触发的事件不是
hidden
,而是
hidden.bs.modal
(请参阅标题“事件”下的内容)。所以这个

$('popupSelect')。在('hidden',function(){…

不会开火。将其更改为

$('popupSelect').on('hidden.bs.modal',function(){…

我也不清楚为什么它在一个名为“removeModalContent”的函数中。您真的想在加载时设置事件处理程序。在当前情况下,您需要做的是调用该函数来设置事件侦听器


正如我所说,对于您的特定情况/问题,我并不完全确定,因此,如果这没有帮助,或者我遗漏了什么,请让我知道,我会再看一看。

当我使用modals时,我总是喜欢在弹出任何用户交互之前清除它。我就是这样做的:

1) 订阅按钮点击事件以显示模式窗口:

$("#btnSearchCustomer").click(function () {
        searchCustomers($(this));
    });
2) 功能searchCustomers将显示弹出窗口

function searchCustomers(btn) {
    btn.attr("disabled", "disabled"); // disables the button to avoid loading data more than once
    clearSearchForm(); // clears any user input
    // checks if the modal has all the data loaded (to avoid loading on start)
    if (!searchForIsLoaded) {
        loadSearchForm(); // loads any necessary data from the DB using AJAX
        searchForIsLoaded = true;
    }
    $('#mdlSearchForm').modal('show'); // shows the modal window
    btn.removeAttr("disabled"); // enables the button again
}
您需要实现函数clearSearchForm来清除用户修改的任何字段

3) 订阅模式窗口上的OK按钮,并对用户输入进行操作

4) 隐藏模态形式


我希望它有帮助。

$(this.data(“”)?我尝试了
$(this.removeData('.modal');
仍然不起作用试试这个$('#popupSelect')。on('hidden.bs.modal',function(){//do you want});你应该挂接到
显示的.bs.modal
事件。重复的
function searchCustomers(btn) {
    btn.attr("disabled", "disabled"); // disables the button to avoid loading data more than once
    clearSearchForm(); // clears any user input
    // checks if the modal has all the data loaded (to avoid loading on start)
    if (!searchForIsLoaded) {
        loadSearchForm(); // loads any necessary data from the DB using AJAX
        searchForIsLoaded = true;
    }
    $('#mdlSearchForm').modal('show'); // shows the modal window
    btn.removeAttr("disabled"); // enables the button again
}