[英]PHP onclick confirm to Sweet Alert 2 confirmation
I need your help here please.I have a button which is echoed by a PHP file to a HTML file. 我在这里需要您的帮助。我有一个按钮,PHP文件将其呼应为HTML文件。 When the button is clicked it uses window
confirm()
method but I want to use a sweet alert 2 modal to be displayed with yes or no option in the HTML file. 当单击按钮时,它使用窗口
confirm()
方法,但是我想使用在HTML文件中以yes或no选项显示的甜蜜警报2模式。
Does anyone have any idea how I can make this work? 有谁知道我如何进行这项工作?
PHP echo: PHP回显:
$row['handler'] = "<a class=\"btn btn-detail btn-small\" href=\"user.php?act=cancel_order&order_id=".$row['order_id'].
"\" onclick=\"if (!confirm('".$GLOBALS['_LANG']['confirm_cancel'].
"')) return false;\">".$GLOBALS['_LANG']['cancel'].
"</a>";
Do I need to add the script to a external file and call it inside PHP or there is better way to do this ? 我是否需要将脚本添加到外部文件并在PHP中调用它,或者有更好的方法呢?
I have just modified your code. 我刚刚修改了您的代码。
$row['handler'] = '<a class="btn btn-detail btn-small" href="javascript:;" onclick="confirmation(\''.$GLOBALS['_LANG']['confirm_cancel'].
'\',\'user.php?act=cancel_order&order_id='.$row['order_id'].
'\')">'.$GLOBALS['_LANG']['cancel'].
'</a>';
And your javascript function will looks like this 而且您的javascript函数将如下所示
function confirmation(text,text2)
{
swal({
title: text,
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, cancel!',
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
buttonsStyling: false
}).then(function () {
location.href=text2;
}, function (dismiss) {
return false;
})
}
Hope it will work :) 希望它能工作:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.