SweetAlert 不适用于单引号

SweetAlert not working with single quotes

在使用 SweetAlert 时,我在使用单引号时遇到问题,例如下面的代码有效

<script>

function test()
{

Swal.fire({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes, delete it!'
}).then((result) => {
  if (result.value) {
    Swal.fire(
      'Deleted!',
      'Your file has been deleted.',
      'success'
    )
  }
})


}

</script>

但是当它与单引号一起使用时(在 php echo 内)- 它不起作用

正文:"You won't be able to revert this!",=好

文本:“您将无法还原!”,= 不行。

这个谜题有答案吗

您在单词 won't 中有一个未转义的引号。如果你想使用单引号来定义你的字符串,你应该转义它,像这样:'You won\'t be able to revert this!'