【问题标题】:PHP onclick confirm to Sweet Alert 2 confirmationPHP onclick 确认到 Sweet Alert 2 确认
【发布时间】:2017-05-23 06:22:16
【问题描述】:

我需要你的帮助。我有一个由 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 中调用它还是有更好的方法来做到这一点?

【问题讨论】:

  • 阅读引导模式
  • 我已经有一个模态工作,问题是关于在 php 中调用它的最佳方法

标签: javascript php sweetalert sweetalert2


【解决方案1】:

我刚刚修改了你的代码。

$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;
    })
  }

希望它会起作用:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-27
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多