简体   繁体   English

在 SweetAlert2 上自定义 class

[英]Custom class on SweetAlert2

I am using SweetAlert2 version 10.13.0 to display an alert box.我正在使用SweetAlert2 版本 10.13.0来显示警告框。 My problem is that the custom class I placed is not working except for the margin.我的问题是我放置的自定义 class 除了边距外不起作用。 I referred to the documentation of SweetAlert2 still it is not working.我参考了 SweetAlert2 的文档,但它仍然无法正常工作。

Here is my code:这是我的代码:

const swalWithBootstrapButtons = Swal.mixin({
    confirmButtonClass: 'btn btn-danger',
    cancelButtonClass: 'btn btn-dark mr-2',
    buttonsStyling: false,
});
    
swalWithBootstrapButtons.fire({
        title: 'Data Delete',
        text: 'Are you sure that you want to delete this data?',
        icon: 'info',
        showCancelButton: true,
        confirmButtonText: 'Delete Data',
        reverseButtons: true
    }).then((result) => {
        if (result.value) {
           // AJAX HERE    
        }
});

I placed btn-danger the confirm button should be color red and the cancel button should be black but here is the output. The only thing that is working is the mr-2 but the button color is not (please refer to the output) .我放置了 btn-danger,确认按钮应该是红色,取消按钮应该是黑色,但这里是 output。唯一有效的是mr-2 ,但按钮颜色不是(请参考输出)

Output Here Output 这里

Am I missing something or is there anything that I haven't done yet?我是不是遗漏了什么,或者还有什么我还没有做的吗?

As per the documentation, the buttonsStyling option should be outside the object customClass.根据文档,buttonsStyling 选项应该在 object customClass 之外。

const swalWithBootstrapButtons = Swal.mixin({
  customClass: {
    confirmButton: 'btn btn-success',
    cancelButton: 'btn btn-danger mr-2'
  },
  buttonsStyling: false
})

Now, if you can inspect that element on the browser and check if the class is present on the element or not.现在,如果您可以在浏览器上检查该元素并检查元素上是否存在 class。 I can see in the example on the documentation the class names are replaced on the element as it is.我可以在文档的示例中看到 class 名称在元素上被替换为原样。

If you can see your class name there then you have to figure out if your CSS has the same styling rules.如果您可以在那里看到您的 class 名称,那么您必须确定您的 CSS 是否具有相同的样式规则。

See Example查看示例

estou usando a versão sweetalert2 v7.12.15, e estou com problemas aqui:使用 sweetalert2 v7.12.15 版本,使用 com probleas aqui:

const swalWithBootstrapButtons = swal.mixin({ // Uncaught TypeError: swal.mixin is not a function customClass: { confirmButton: 'btn btn-success', cancelButton: 'btn btn-danger' }, buttonsStyling: false }) const swalWithBootstrapButtons = swal.mixin({ // 未捕获类型错误:swal.mixin 不是 function customClass: { confirmButton: 'btn btn-success', cancelButton: 'btn btn-danger' }, buttonsStyling: false })

                swalWithBootstrapButtons.fire({
                  title: 'Are you sure?',
                  text: "You won't be able to revert this!",
                  icon: 'warning',
                  showCancelButton: true,
                  confirmButtonText: 'Yes, delete it!',
                  cancelButtonText: 'No, cancel!',
                  reverseButtons: true
                }).then((result) => {
                  if (result.isConfirmed)
                  {
                    var jan = window.open("http://127.0.0.1:8000/cadastro/pessoa", "janelaNova");
                  }
                  else if
                  (
                    /* Read more about handling dismissals below */
                    result.dismiss === swal.DismissReason.cancel
                  )
                  {
                    ///
                  }
                })

Alguém pode me ajudar. Alguém pode me ajudar。 Obrigado奥布里加多

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

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