简体   繁体   中英

Change ajax default alert box style

Is there a way I could change the default ajax alert box? I currently have the code below, that deletes a user and reloads the current page. It works, but I would like to add some styling to the alert box that it triggers before the user is actually deleted.

  function deleteUser(id) {
      var action = confirm("Are you sure you want to delete this student?");

      if (action != false) {
        $.ajax({
           url: '{% url "student-delete" %}',
           data: {
            'id': id,
        },
        dataType: 'json',
        success: function (data) {
            if (data.deleted) {
              $("#userTable #user-" + id).remove();
              window.location.reload()
            }
        }
    });
  }
}

I tried changing the confirm to

    function deleteUser(id) {
      var action = bootstrap.confirm("Are you sure you want to delete this student?");
  if (action != false) {
    $.ajax({
       url: '{% url "student-delete" %}',
       data: {
        'id': id,
    },
    dataType: 'json',
    success: function (data) {
        if (data.deleted) {
          $("#userTable #user-" + id).remove();
          window.location.reload()
        }
    }
});

} }

This displayed nothing.

You cannot style the custom confirmation box. It varies from browser to browser. If you want something custom you can build out one yourself using HTML and CSS. For example attach click events for yes button and for a no button and based on that you can make the delete

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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