【问题标题】:jquery-confirm - How to send href link to browserjquery-confirm - 如何将href链接发送到浏览器
【发布时间】:2017-01-27 08:44:16
【问题描述】:

我正在使用这个不错的插件 jquery-confirm v3.0.3 (http://craftpip.github.io/jquery-confirm/) 来确认操作

但是当使用下面的代码时,我的链接中的 href 操作在我按下 OK 按钮时没有执行?

我做错了什么?感谢您的帮助...

<a class="delItem" href="?del=true&id=1">Supprimer</a>

$('a.delItem').confirm({
            title: 'Confirmer cette action',
            content: '',
            animation: 'left',
            theme: 'light',
            type: 'red',
            autoClose: 'cancel|10000',
            buttons: {
                confirm: {
                    text: 'OK'
                },
                cancel: {
                    text: 'Annuler',
                    action: function () {
                    //$.alert('action is canceled');
                    }
                }
            }
        });

【问题讨论】:

  • 您的确认按钮应该设置一个动作吗?

标签: jquery href alert confirm


【解决方案1】:

只需在确认块内添加操作功能(如取消)即可:

window.location.href = $(this).attr("href");

【讨论】:

    【解决方案2】:

    您是否尝试添加

    location.href = this.$target.attr('href');
    

    在你的 OK 按钮中

    $('a.delItem').confirm({
      title: 'Confirmer cette action',
      content: '',
      animation: 'left',
      theme: 'light',
      type: 'red',
      autoClose: 'cancel|10000',
      buttons: {
        confirm: {
          text: 'OK',
          location.href = this.$target.attr('href')
        },
        cancel: {
          text: 'Annuler',
          action: function () {
            //$.alert('action is canceled');
          }
        }
      }
    });
    

    【讨论】:

    • 感谢与 location.href = this.$target.attr('href');但是如果我想通过 POST 请求?在 jquery-confirm 的最后一个版本中,不需要 location.href = this.$target.attr('href');
    • @Chris 我从来没有使用过jquery-confirm,但似乎你可以使用“正常”ajax request craftpip.github.io/jquery-confirm/#content-loaded 所以只需设置方法和数据,如下所述:api.jquery.com/jquery.ajax/#entry-examples跨度>
    • 谢谢。只是这个插件的第 2 版之前处理了 POST 请求。我现在要使用 $.ajax 方法;))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2010-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多