【问题标题】:Clear All Modal Popup data on data-dismissal in Bootstrap在 Bootstrap 中清除所有关于数据关闭的 Modal Popup 数据
【发布时间】:2020-10-13 19:12:27
【问题描述】:

我在单个页面上有多个引导模式弹出窗口(modal1、modal2、modal3),我想在关闭每个打开的模式时清除或重置表单。我正在使用

$('.modal').on('hidden.bs.modal', function () {
  $('#modal1 form')[0].reset();
}); 

当我关闭 modal1 弹出窗口时,这可以正常工作,上面的代码会重置表单,但我想为应用程序中的所有模式编写通用隐藏代码,例如

 $('.modal').on('hidden.bs.modal', function () {
    $('.commonClass form')[0].reset();
}); 

希望此代码在关闭任何模式弹出窗口时重置表单模式,但在使用 commonclass(在所有模式弹出窗口中)清除表单时它无法按预期工作。有没有办法使用 commonClass 清除表单

【问题讨论】:

  • $('.commonClass form')[0] 您只是用 [0] 重置第一个表单,请尝试将其删除。
  • get error $().reset is not a function when removed [0] @Toxnyc

标签: jquery twitter-bootstrap bootstrap-4 bootstrap-modal


【解决方案1】:

循环遍历所有表单对我有用

    $('.commonClass form').each(function() { this.reset() });

【讨论】:

    猜你喜欢
    • 2017-12-04
    • 2013-05-04
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    • 2016-01-03
    • 2023-02-19
    • 1970-01-01
    • 2013-03-19
    相关资源
    最近更新 更多