SweetAlert 中未显示按钮文本
Button text not showing in SweetAlert
我真的不知道我做错了什么。 SweetAlert 运行良好,但不显示按钮文本。
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary file!",
icon: "warning",
buttons: true,
dangerMode: true,
});
答案在这里
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes',
cancelButtonText: "No",
closeOnConfirm: false,
closeOnCancel: false
},
或
swal({
text: "Once deleted, you will not be able to recover this imaginary file!",
buttons: ["Yes", "No"],
});
或
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
swal("Are you sure you want to do this?", {
buttons: ["Yes", "No"],
});
尝试创建一个干净的 html 页面并像这样尝试一下:
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary file!",
icon: "warning",
buttons: true,
dangerMode: true,
})
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
可能问题出在您页面中的其他脚本上,因为您的代码应该可以正常工作,您可以尝试像这样使用 Sweetalert2:
Swal.fire({
title: 'Do you want to save the changes?',
showCancelButton: true,
confirmButtonText: 'CONFIRM',
denyButtonText: `CANCEL`,
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
// confirm button pressed
console.log("confirm")
} else if (result.isDismissed) {
// deny button pressed
console.log("deny")
}
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.1.9/dist/sweetalert2.all.min.js"></script>
编辑:
尝试在您的 HTML 页面中添加 jquery,然后再像这样导入其他脚本:
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
我真的不知道我做错了什么。 SweetAlert 运行良好,但不显示按钮文本。
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary file!",
icon: "warning",
buttons: true,
dangerMode: true,
});
答案在这里
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes',
cancelButtonText: "No",
closeOnConfirm: false,
closeOnCancel: false
},
或
swal({
text: "Once deleted, you will not be able to recover this imaginary file!",
buttons: ["Yes", "No"],
});
或
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
swal("Are you sure you want to do this?", {
buttons: ["Yes", "No"],
});
尝试创建一个干净的 html 页面并像这样尝试一下:
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary file!",
icon: "warning",
buttons: true,
dangerMode: true,
})
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
可能问题出在您页面中的其他脚本上,因为您的代码应该可以正常工作,您可以尝试像这样使用 Sweetalert2:
Swal.fire({
title: 'Do you want to save the changes?',
showCancelButton: true,
confirmButtonText: 'CONFIRM',
denyButtonText: `CANCEL`,
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
// confirm button pressed
console.log("confirm")
} else if (result.isDismissed) {
// deny button pressed
console.log("deny")
}
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.1.9/dist/sweetalert2.all.min.js"></script>
编辑:
尝试在您的 HTML 页面中添加 jquery,然后再像这样导入其他脚本:
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>