【问题标题】:closing and removeData not working in modal关闭和 removeData 在模式下不起作用
【发布时间】:2016-04-18 11:56:58
【问题描述】:

我使用了 jquery 1.12.2 和 Bootstrap 3。

这是我的代码,

$('body').on('hidden.bs.modal', '#wideModal', function () {
    $('#wideModal .modal-body').empty();
    $('#wideModal .modal-content').removeData('bs.modal');
    $('#wideModal .modal-body').html("");
    $('#wideModal').data('bs.modal', null);
});

它仍然没有删除前一个模态的内容。 我不能使用 option.remote。 要将数据放置到我的模态中,我使用了 JavaScript。

这是代码,

$('#wideModal .modal-body').html(str);

如何彻底删除模态框的内容?

【问题讨论】:

    标签: javascript jquery twitter-bootstrap modal-dialog


    【解决方案1】:

    如果你想清空输入字段,你可以试试这个

    $('#myModal').on('hidden.bs.modal', function () {
            $('.modal-body').find('textarea,input').val('');
    });
    

    【讨论】:

    • 我没有输入字段
    【解决方案2】:

    Jquery site 说 .removeData() 方法允许我们删除之前使用 .data() 设置的值。

    我认为 .remove() 应该可以工作,因为它会从 DOM 中删除匹配的元素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多