【问题标题】:Unable to removedata from modal on close.Showing same content everytime关闭时无法从模式中删除数据。每次都显示相同的内容
【发布时间】:2014-12-01 08:53:18
【问题描述】:

关闭时无法从模式中删除数据。每次都显示相同的内容

$('body').on('hidden.bs.modal', '.modal', function () {
  $(this).removeData('bs.modal');
});

这个功能也不行。

【问题讨论】:

  • 有什么方法可以在每次重新启动时清除模态缓存。
  • 您使用的是哪个版本的引导程序?

标签: jquery twitter-bootstrap


【解决方案1】:

当我将数据传递给相同的模式并删除内容时,遇到了同样的问题。最好的解决方案,唯一的办法就是使用 bootBox

http://bootboxjs.com/

bootbox.dialog({
  message: "I am a custom dialog",
  title: "Custom title",
  buttons: {
    success: {
      label: "Success!",
      className: "btn-success",
      callback: function() {
        Example.show("great success");
      }
    },
    danger: {
      label: "Danger!",
      className: "btn-danger",
      callback: function() {
        Example.show("uh oh, look out!");
      }
    },
    main: {
      label: "Click ME!",
      className: "btn-primary",
      callback: function() {
        Example.show("Primary button");
      }
    }
  }
});

【讨论】:

  • 我不能在这里使用 bootbox。有几个下拉菜单和输入类型。
【解决方案2】:

以这种方式尝试 Bootstrap v3.2.0

$(document).on("hidden.bs.modal", function (e) {
    $(e.target).removeData("bs.modal").find(".modal-content").empty();
});

通用模态示例

<div class="modal hide" id="">

    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">x</button>

    </div>    

    <div class="modal-body">

    </div>

    <div class="modal-footer">

    </div>

</div>

【讨论】:

  • faby 检查我的 html jsfiddle.net/ovtj3jxu 我对上面脚本中的 div Id 完全感到困惑。
  • @shakun 您的代码完全无法访问。请只输入相关代码并加载外部库
  • 您可以给出使用上述脚本的任何示例。主
    id
  • 不工作。现在我正在使用这个 $('.md-close').click(function() { window.location.reload() });
【解决方案3】:

我终于可以做出自己的作品了

应该是。

        $('body').on('hide.bs.modal', '.modal', function (e) {
        $(this).find('form').trigger("reset");
    });

I cant clear form data from bootstrap modalSadikhasan 用户这个帖子中,你需要清除表单数据但 $(this) 是模态 div,所以你需要在模态中找到表单并重置它。

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签