Jquery,从点击中获取url并传递给对话框中的确认按钮

标签 jquery dialog click href

我有这个 jquery 代码:

$("#deletec-box").dialog({
     autoOpen: false,
     resizable: false,
     height:230,
     modal: true,
     buttons: {
      "Confirm": function() {
          window.location = 'hrefurlfromclick';
          $(this).dialog("close");
      },
      Cancel: function() {
          $(this).dialog("close");
      }
     }
    });

    $("#deletec-confirm").click(function() {
        $("#deletec-box").dialog("open");
        return false;
    });

然后在页面中我有一个调用对话框的链接:

<a href="?action=delc&cid=2" id="deletec-confirm">Delete</a>

我的问题是如何获取 href 的值,以便如果用户确认它会加载他们最初单击的链接?

最佳答案

您可以通过以下方式获取 href 属性:$('#deletec-confirm').attr('href');

您的代码现在如下所示:

$("#deletec-box").dialog({
    autoOpen: false,
    resizable: false,
    height:230,
    modal: true,
    buttons: {
        "Confirm": function() {
            window.location = $('#deletec-confirm').attr('href');
            $(this).dialog("close");
        },
        Cancel: function() {
            $(this).dialog("close");
        }
    }
});

$("#deletec-confirm").click(function() {
    $("#deletec-box").dialog("open");
    return false;
});

关于Jquery,从点击中获取url并传递给对话框中的确认按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6575957/

相关文章:

javascript - HighChart - 可以在标题和副标题之间画线

java - 如何向 GWT ButtonCell 添加点击处理程序?

javascript - 点击事件传递参数

javascript - html5 Canvas 点击贝塞尔路径形状检测

javascript - 通过单击外部关闭 Dojo 对话框

c# - 单击 asp.net 后退按钮管理表单数据(通过 Session 或 Viewstate 处理除外)

jquery - 使图像从右到左重新调整大小

javascript - jqgrid设置一行的背景

c++ - 如何使用 WTL 或 Windows SDK(无 MFC)创建 TitleAreaDialog?

javascript - 在jquery中创建没有id的对话框