首页 > 解决方案 > 一个接一个地运行多个sweetalerts

问题描述

我试图在彼此之后运行多个sweetalerts,但我现在拥有的代码只是执行最后一个。有谁知道为什么以及如何解决这个问题?

const { value: inhalt } = Swal.fire({
  title: 'Neue Ladegüter',
  text: 'Geben Sie einen Inhalt an:',
  input: 'text',
  showCancelButton: true,
  inputValidator: (value) => {
    if (!value) {
      return 'Field cannot be empty'
    }
  }
});

const { value: beschreibung } = Swal.fire({
  title: 'Neue Ladegüter',
  text: 'Geben Sie eine Beschreibung an:',
  input: 'text',
  showCancelButton: true,
  inputValidator: (value) => {
    if (!value) {
      return 'Field cannot be empty'
    }
  }
});

标签: javascripthtmlsweetalert

解决方案


当您调用警报时,它将关闭最后一个,然后打开新的。它使用一个容器来显示警报。你应该在最后一个警报的响应上调用其他警报。

编辑:添加示例

Swal.fire({
  title: 'Neue Ladegüter',
  text: 'Geben Sie einen Inhalt an:',
  input: 'text',
  showCancelButton: true,
  inputValidator: (value) => {
    if (!value) {
      return 'Field cannot be empty'
    }
  }
}).then((res)=>{
    Swal.fire({
      title: 'Neue Ladegüter',
      text: 'Geben Sie eine Beschreibung an:',
      input: 'text',
      showCancelButton: true,
      inputValidator: (value) => {
        if (!value) {
          return 'Field cannot be empty'
        }
      }
    });
});


推荐阅读