首页 文章

PHP onclick确认Sweet Alert 2确认

提问于
浏览
-1

我需要你的帮助 . 我有一个按钮,由PHP文件回显到HTML文件 . 单击该按钮时,它使用窗口 confirm() 方法,但我想使用甜蜜警报2模式在HTML文件中显示是或否选项 .

有谁知道我怎么能做这个工作?

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>";

我是否需要将脚本添加到外部文件并在PHP中调用它或者有更好的方法来执行此操作?

1 回答

  • 2

    我刚刚修改了你的代码 .

    $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>';
    

    你的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;
        })
      }
    

    希望它会工作:)

相关问题