【问题标题】:Deletion of class by jsjs删除类
【发布时间】:2018-02-19 01:20:14
【问题描述】:

我会根据情况在 HTML 2 中显示语句。这些是 Bootstrap 类中的女主角:alert。这是一个没有超载的页面。因此,我希望在新数据发送后看到旧通信消失。如何做到这一点,以便类 div alert 消失。

function forgotUsername() {
    $('.panel-body').removeClass('alert');
    var forgotUsernameDTO = {"email":$('#email').val()};
    $.ajax({
        type: 'PUT',
        url: '/forgotUsername',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: JSON.stringify(forgotUsernameDTO),
        success: function (result) {
            $('#forgotUsernameForm')
                .before('<div class="alert alert-dismissable alert-success">'
                        + '<span th:text="#{forgotUsername.success}">An e-mail has been successfully sent. Please allow a few minutes for it to get to your inbox!</span>'
                        + '</div>');
        },
        error: function (error) {
            $('#forgotUsernameForm')
                .before('<div class="alert alert-dismissable alert-danger">'
                        + '<span th:text="#{forgotUsername.error}">No username found associated with that e-mail!</span>'
                        + '</div>');
        }
    });
}

【问题讨论】:

    标签: javascript jquery html ajax twitter-bootstrap


    【解决方案1】:

    你在做

    $('.panel-body').removeClass('alert');
    

    $.removeClass() 函数会尝试从元素中删除类,但实际上并没有删除元素。我想你想要

    $('.alert').remove();    //selects all elements with the "alert" class, then removes them from the page
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-01
      • 1970-01-01
      • 2021-10-14
      相关资源
      最近更新 更多