下面是我的函数,我正在获取值作为参数。
基于我需要显示自定义文本的值。下面是我的代码。
buttonClicked(value) {
console.log(value);
swal({
title: 'Are you sure?',
text: 'ssss',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Delete',
// closeOnConfirm: true
}).then((result) => {
if (result === true) {
}
}, function (dismiss) { });
}
最佳答案
如果您使用 sweetalert2,那么您的代码存在一些问题。 sweetalert 的取消按钮操作未按预期工作,您需要按如下所示进行修改。您还可以根据从函数传递的值将自定义文本的值存储在变量中,如下所示
function buttonClicked(value){
console.log(value);
var customText;
if(value =='First button'){
customText = "first button clicked";
}
else if(value =='Second button'){
customText = "second button clicked";
}
swal({
title: 'Are you sure?',
text: customText,
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Delete',
}).then((result) => {
if (result.value) {
alert("Deleted");
}
else if(result.dismiss == swal.DismissReason.cancel) {
alert('cancel');
}
});
}
<link href="https://cdn.jsdelivr.net/npm/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cdbebaa8a8b9aca1a8bfb9ff8dfae3fff9e3fc" rel="noreferrer noopener nofollow">[email protected]</a>/dist/sweetalert2.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f4c485a5a4b5e535a4d4b0d7f08110d0b110e" rel="noreferrer noopener nofollow">[email protected]</a>/dist/sweetalert2.all.min.js"></script>
<button onclick="buttonClicked('First button')">
First button
</button> <br>
<button onclick="buttonClicked('Second button')">
Second button
</button>
这是一个工作 fiddle http://jsfiddle.net/zvseqond/1/
关于angular - 如何更改 Angular 中甜蜜警报的文本属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50986591/