jQuery-从弹出窗口打开href

jQuery-从弹出窗口打开href,jquery,hyperlink,popup,click,href,Jquery,Hyperlink,Popup,Click,Href,这是我的第一个问题,让我们看看进展如何 那么,下面是: HTML: 所以,问题是,我有一个表,其中有一列可以删除、复制或添加行,我想在每次您想要删除、复制或添加行时都弹出一个确认窗口。 弹出窗口可以工作,但当我想按“是”时,它不会返回到我按下的链接(在我的示例中是google链接) 我正在使用动态链接,因此无法直接指向,行(及其href)是动态生成的 如何在弹出窗口的“是”选项中“单击”链接的href 顺便说一句,我试过在这一部分: function callback(value) {

这是我的第一个问题,让我们看看进展如何

那么,下面是:

HTML:

所以,问题是,我有一个表,其中有一列可以删除、复制或添加行,我想在每次您想要删除、复制或添加行时都弹出一个确认窗口。 弹出窗口可以工作,但当我想按“是”时,它不会返回到我按下的链接(在我的示例中是google链接)

我正在使用动态链接,因此无法直接指向,行(及其href)是动态生成的

如何在弹出窗口的“是”选项中“单击”链接的href

顺便说一句,我试过在这一部分:

function callback(value) {
    if (value) {
        $(this).attr('href');

    } else {
        alert("Rejected");
    }
}
我试过:
$(this.attr('href')
window.location=$(this.attr('href'),等等。

您有两个问题:

  • callback()
    中,
    这不是您所认为的
  • .attr('something')
    是一个getter。它只检索一个值
  • 试试这个:

    $('.confirmDelete').click(OpenDeleteDialog);
    //Delete Column functionallity
    function OpenDeleteDialog() {
    
        var $link = $(this); //keep track of the element that was clicked
    
        $("#confirmDeleteBox").html("Confirm Delete Dialog Box");
    
        $("#confirmDeleteBox").dialog({
            resizable: false,
            modal: true,
            title: "Modal",
            height: 250,
            width: 400,
            buttons: {
                "Yes": function () {
                    $(this).dialog('close');
                    callback(true, $link); //pass the reference to the element
                },
                "No": function () {
                    $(this).dialog('close');
                    callback(false);
                }
            }
        });
        event.preventDefault();
    }
    
    function callback(confirmed, $el) {
        if (confirmed) {
            window.location = $el.attr('href'); //change the page's location    
        } else {
            alert("Rejected");
        }
    }
    

    试试这个

    $('.confirmDelete').click(OpenDeleteDialog);
    //Delete Column functionallity
    var currentHref;   //store href of current selected link
    
    function callback(value) {
        if (value) {
            window.location = $(currentHref).attr('href');
    
        } else {
            alert("Rejected");
        }
    }
    
    function OpenDeleteDialog(event) {
    
        currentHref = event.target;  //get the clicked element
    
        $("#confirmDeleteBox").html("Confirm Delete Dialog Box");
    
        $("#confirmDeleteBox").dialog({
            resizable: false,
            modal: true,
            title: "Modal",
            height: 250,
            width: 400,
            buttons: {
                "Yes": function () {
                    $(this).dialog('close');
                    callback(true);
                },
                "No": function () {
                    $(this).dialog('close');
                    callback(false);
                }
            }
        });
        event.preventDefault();
    }
    

    • 使用
      event.target
      获取当前链接的值
    • 您还可以使用传递当前选定元素的值

      $('.confirmDelete').click(function(){
          OpenDeleteDialog(this);
      );
      
      function OpenDeleteDialog(obj){..}
      

    是否要单击链接
    ?是。这是一个确认。当您单击“删除”链接时,我希望弹出窗口显示并询问您“是”或“否”(目前正在工作),当您单击“是”时,它将获得原始链接(删除链接)的“href”值非常非常非常非常感谢。工作做得很好。我从一开始就搞错了。谢谢你!!谢谢你的回答。我加入了另一个并锻炼了,没有尝试你的,因为我很忙(工作,工作,工作),但我非常感谢你的关注和努力。非常感谢!!!:D
    $('.confirmDelete').click(OpenDeleteDialog);
    //Delete Column functionallity
    var currentHref;   //store href of current selected link
    
    function callback(value) {
        if (value) {
            window.location = $(currentHref).attr('href');
    
        } else {
            alert("Rejected");
        }
    }
    
    function OpenDeleteDialog(event) {
    
        currentHref = event.target;  //get the clicked element
    
        $("#confirmDeleteBox").html("Confirm Delete Dialog Box");
    
        $("#confirmDeleteBox").dialog({
            resizable: false,
            modal: true,
            title: "Modal",
            height: 250,
            width: 400,
            buttons: {
                "Yes": function () {
                    $(this).dialog('close');
                    callback(true);
                },
                "No": function () {
                    $(this).dialog('close');
                    callback(false);
                }
            }
        });
        event.preventDefault();
    }
    
    $('.confirmDelete').click(function(){
        OpenDeleteDialog(this);
    );
    
    function OpenDeleteDialog(obj){..}