如何清理(销毁)Twitter Bootstrap 3.2模态表单内容

Rey*_*rPM 2 html javascript css jquery twitter-bootstrap

我有一个Twitter Bootstrap模式,我在其中显示一些表单元素.我正在尝试清理BS上隐藏/关闭的所有表单元素内容但是我做错了,因为下面的代码都不起作用:

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

$('.modal').on('hide.bs.modal', function () {
    $('.modal').removeData();
})

$("#addNorma").on('hidden.bs.modal', function () {
    $(this).data('bs.modal', null);
});
Run Code Online (Sandbox Code Playgroud)

也许这种"破坏"是针对别的东西,我不明白.无论如何这里是一个小提琴,我显示问题:

  • 打开模态并在任何输入中写入内容
  • 关闭模态
  • 再次打开模态,您将看到内容

我想避免这种行为,怎么样?

dfs*_*fsq 5

如何简单地将表单重置为原始状态,也许它对您有用

$("#addNorma").on('hide.bs.modal', function () {
    $(this).find('form')[0].reset();
});
Run Code Online (Sandbox Code Playgroud)

演示:http://jsfiddle.net/kk3xr15m/1/