简体   繁体   English

从 Bootstrap Modal 中删除数据

[英]Remove data from Bootstrap Modal

Referred this links Link1 Link 2 but not able clear the data's.引用此链接Link1 Link 2但无法清除数据。

I am using bootstrap modal window in my web application.我在我的 Web 应用程序中使用引导模式窗口。 When modal is closed (triggered hidden event to clear the data), previously entered data's are not cleared.当模态关闭时(触发隐藏事件以清除数据),之前输入的数据不会被清除。

Here is the fiddle ` what i tried.Even I tried with form reset but not get success.这是我尝试过的小提琴。即使我尝试过表单重置但没有成功。

$("#modal").on('hidden.bs.modal', function (e) {
        $('#modal_form')[0].reset();
        $("#modal").removeData('bs.modal');
    });
    $("#modal").click(function() {

        $("#modal").removeData('bs.modal');
        $("#modal").modal();
    });

You need to reset $("#myModal form")[0] instead of $("#myModal form")您需要重置$("#myModal form")[0]而不是$("#myModal form")

$("#myModal").on('hidden.bs.modal', function (e) { 
            $("#myModal form")[0].reset();
            $("#myModal form").find('span[style="color:red;"]').text(''); //reset error spans

          });

If you give the form an ID, you can do the following in jQuery.如果你给表单一个 ID,你可以在 jQuery 中执行以下操作。 You can also add a class to your error spans and reset all of them at the same time.您还可以向错误范围添加一个类并同时重置所有这些类。

$("#myModal").on('hidden.bs.modal', function (e) {
    $("#form").trigger('reset');
    $("#myModal .error").html('');
});


<span style="color:red;" id="username_span" class="error"></span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM